Changeset 357 for lang/ruby/module-pluggable
- Timestamp:
- 10/04/07 05:35:46 (4 years ago)
- Location:
- lang/ruby/module-pluggable
- Files:
-
- 4 added
- 2 modified
-
examples/plugins (added)
-
examples/plugins/hoge_hoge.rb (added)
-
examples/plugins/test.rb (added)
-
examples/simple.rb (added)
-
lib/module/pluggable.rb (modified) (3 diffs)
-
test/test_module-pluggable.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/module-pluggable/lib/module/pluggable.rb
r355 r357 6 6 module Module::Pluggable 7 7 DEFAULT_OPTS = { 8 :name => :plugins,9 8 :search_path => "plugins", 10 9 :except => /_$/, … … 12 11 }.freeze 13 12 14 def pluggable( o={})13 def pluggable(name=:plugins, o={}) 15 14 opts = DEFAULT_OPTS.merge(o) 16 opts[:search_path] = o[:name] ? o[:name].to_s : opts[:name].to_s unless opts[:search_path]15 opts[:search_path] = name ? name.to_s : opts[:name].to_s unless opts[:search_path] 17 16 18 17 m = Marshal.dump(opts) 19 18 class_eval <<-EOS 20 def #{ opts[:name]}21 @#{ opts[:name]} ||= Module::Pluggable::Plugins.new(Marshal.load('#{m}'))19 def #{name} 20 @#{name} ||= Module::Pluggable::Plugins.new(Marshal.load('#{m}')) 22 21 end 23 22 EOS … … 120 119 end 121 120 121 def method_missing(name, *args) 122 call(name, *args) 123 end 124 122 125 # foo/foo_bar => Foo::FooBar 123 126 def file2klass(str) -
lang/ruby/module-pluggable/test/test_module-pluggable.rb
r356 r357 28 28 path = @plugins_dir 29 29 test = Class.new { 30 pluggable : name => :plugins, :search_path => path30 pluggable :plugins, :search_path => path 31 31 }.new 32 32 assert test.plugins["Test"] … … 36 36 test.plugins.call(:instance_variable_set, :@test_obj, obj) 37 37 assert_equal obj, test.plugins["Test"].instance_variable_get(:@test_obj) 38 39 assert_equal "This is test plugin.", test.plugins.description["Test"] 38 40 end 39 41 … … 42 44 assert_raise(Module::Pluggable::Plugins::NotInheritAbstractClassError) do 43 45 test = Class.new { 44 pluggable : name => :plugins, :search_path => path, :base_class => PluginBase46 pluggable :plugins, :search_path => path, :base_class => PluginBase 45 47 }.new 46 48 test.plugins … … 53 55 assert_nothing_raised do 54 56 test = Class.new { 55 pluggable : name => :plugins, :search_path => path, :base_class => PluginBase57 pluggable :plugins, :search_path => path, :base_class => PluginBase 56 58 }.new 57 59 test.plugins
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)