Show
Ignore:
Timestamp:
10/04/07 05:35:46 (4 years ago)
Author:
cho45
Message:

lang/ruby/module-pluggable/test/test_module-pluggable.rb,
lang/ruby/module-pluggable/lib/module/pluggable.rb:

インターフェイスを少し変更。第一引数に name をとるように。
method_missing 時に call に委譲するように

lang/ruby/module-pluggable/examples/plugins,
lang/ruby/module-pluggable/examples/plugins/test.rb,
lang/ruby/module-pluggable/examples/plugins/hoge_hoge.rb,
lang/ruby/module-pluggable/examples/simple.rb:

例をついか

Location:
lang/ruby/module-pluggable
Files:
4 added
2 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/module-pluggable/lib/module/pluggable.rb

    r355 r357  
    66module Module::Pluggable 
    77        DEFAULT_OPTS = { 
    8                 :name        => :plugins, 
    98                :search_path => "plugins", 
    109                :except      => /_$/, 
     
    1211        }.freeze 
    1312 
    14         def pluggable(o={}) 
     13        def pluggable(name=:plugins, o={}) 
    1514                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] 
    1716                 
    1817                m = Marshal.dump(opts) 
    1918                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}')) 
    2221                        end 
    2322                EOS 
     
    120119                end 
    121120 
     121                def method_missing(name, *args) 
     122                        call(name, *args) 
     123                end 
     124 
    122125                # foo/foo_bar => Foo::FooBar 
    123126                def file2klass(str) 
  • lang/ruby/module-pluggable/test/test_module-pluggable.rb

    r356 r357  
    2828                path = @plugins_dir 
    2929                test = Class.new { 
    30                         pluggable :name => :plugins, :search_path => path 
     30                        pluggable :plugins, :search_path => path 
    3131                }.new 
    3232                assert test.plugins["Test"] 
     
    3636                test.plugins.call(:instance_variable_set, :@test_obj, obj) 
    3737                assert_equal obj, test.plugins["Test"].instance_variable_get(:@test_obj) 
     38 
     39                assert_equal "This is test plugin.", test.plugins.description["Test"] 
    3840        end 
    3941 
     
    4244                assert_raise(Module::Pluggable::Plugins::NotInheritAbstractClassError) do 
    4345                        test = Class.new { 
    44                                 pluggable :name => :plugins, :search_path => path, :base_class => PluginBase 
     46                                pluggable :plugins, :search_path => path, :base_class => PluginBase 
    4547                        }.new 
    4648                        test.plugins 
     
    5355                assert_nothing_raised do 
    5456                        test = Class.new { 
    55                                 pluggable :name => :plugins, :search_path => path, :base_class => PluginBase 
     57                                pluggable :plugins, :search_path => path, :base_class => PluginBase 
    5658                        }.new 
    5759                        test.plugins