Show
Ignore:
Timestamp:
10/06/07 08:55:05 (4 years ago)
Author:
cho45
Message:

lang/ruby/module-pluggable/Rakefile,
lang/ruby/module-pluggable/lib/module/pluggable.rb,
lang/ruby/module-pluggable/README,
lang/ruby/module-pluggable/examples/simple.rb,

ドキュメントの更新

lang/ruby/module-pluggable/lib/module/pluggable.rb:

klass2file/file2klass を private に

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

Legend:

Unmodified
Added
Removed
  • lang/ruby/module-pluggable/README

    r366 r385  
    1 README for module-pluggable 
    2 =========================== 
     1= README for module-pluggable 
    32 
    4 see examples. 
     3module-pluggable provides plugin system for classes. 
     4 
     5== Installation 
     6 
     7=== Archive Installation 
     8 
     9        rake install 
     10 
     11=== Gem Installation 
     12 
     13        gem install module-pluggable 
     14 
     15=== Subversion Repository 
     16 
     17Hosted by CodeRepos[http://coderepos.org/share/browser/lang/ruby/module-pluggable] 
     18 
     19        svn co http://svn.coderepos.org/share/lang/ruby/module-pluggable/ 
     20 
     21== Examples 
     22 
     23        class APluggableClass 
     24                pluggable :plugins 
     25 
     26                def initialize 
     27                        plugins.init(self) 
     28                end 
     29 
     30                def say 
     31                        plugins.say("hello") 
     32                end 
     33        end 
     34 
     35see examples/simple.rb. 
     36 
     37== Copyright 
     38 
     39Author::    cho45 <cho45@lowreal.net> 
     40Copyright:: copyright (c) 2007 cho45 www.lowreal.net 
     41License::   Ruby's 
  • lang/ruby/module-pluggable/Rakefile

    r383 r385  
    4545        s.has_rdoc = true 
    4646        s.extra_rdoc_files = ["README", "Changelog"] 
    47         s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/'] 
     47        s.rdoc_options += RDOC_OPTS + ['--exclude', '^(extras)/'] 
    4848        s.summary = DESCRIPTION 
    4949        s.description = DESCRIPTION 
     
    9595        else 
    9696                rdoc.rdoc_files.include('README', 'Changelog') 
     97                rdoc.rdoc_files.include('examples/simple.rb') 
    9798                rdoc.rdoc_files.include('lib/**/*.rb') 
    9899                rdoc.rdoc_files.include('ext/**/*.c') 
  • lang/ruby/module-pluggable/examples/simple.rb

    r366 r385  
    33require "module/pluggable" 
    44 
    5 class SimplePluggable 
    6         # pluggable [name=:plugins] [opts] 
    7         # pluggable make the name of instance method 
    8         # returning instance of Module::Pluggable::Plugin. 
    9         # 
    10         # All loaded plugins are in anonymous module, 
    11         # so you can't access the classes directly, 
    12         # and you can create some plugin-sets 
    13         # without confusing class variables etc. 
    14         pluggable 
     5module Example 
    156 
    16         def initialize 
     7        class SimplePluggable 
     8                # pluggable [name=:plugins] [opts] 
     9                # pluggable make the name of instance method 
     10                # returning instance of Module::Pluggable::Plugin. 
     11                # 
     12                # All loaded plugins are in anonymous module, 
     13                # so you can't access the classes directly, 
     14                # and you can create some plugin-sets 
     15                # without confusing class variables etc. 
     16                pluggable 
     17 
     18                #     plugins.init(self) 
     19                # 
    1720                # `init' method is not defined on Module::Pluggable::Plugin. 
    1821                # undefined methods are delegated to `call' the plugins. 
    1922                # In this case, `plugins.init(self)' is same as `plugins.call(:init, self)'. 
    20                 plugins.init(self) 
     23                def initialize 
     24                        plugins.init(self) 
     25                end 
     26 
     27                def say 
     28                        plugins.each do |name, instance| 
     29                                puts instance.say 
     30                        end 
     31                end 
    2132        end 
    2233 
    23         def say 
    24                 plugins.each do |name, instance| 
    25                         puts instance.say 
    26                 end 
    27         end 
    2834end 
    2935 
    30 SimplePluggable.new.say 
     36Example::SimplePluggable.new.say 
  • lang/ruby/module-pluggable/lib/module/pluggable.rb

    r368 r385  
    1  
    2 #require "module/pluggable" 
     1# Author::    cho45 <cho45@lowreal.net> 
     2# Copyright:: copyright (c) 2007 cho45 www.lowreal.net 
     3# License::   Ruby's 
    34 
    45require "pathname" 
     
    1112        }.freeze 
    1213 
     14        # pluggable make the name of instance method 
     15        # returning instance of Module::Pluggable::Plugin. 
     16        # 
     17        # All loaded plugins are in anonymous module, 
     18        # so you can't access the classes directly, 
     19        # and you can create some plugin-sets 
     20        # without confusing class variables etc. 
     21        #  
     22        #     opts => { 
     23        #         :search_path => name, 
     24        #         :base_class => nil, 
     25        #         :except => /_$/, # not yet 
     26        #     } 
    1327        def pluggable(name=:plugins, o={}) 
    1428                opts = DEFAULT_OPTS.merge(o) 
     
    4458                end 
    4559 
     60                # Load +klass_name+. 
     61                # The plugin is loaded in anonymous module not order to 
     62                # destroy the environments. 
     63                # And remember loaded time for reloading. 
     64                # 
     65                # plugin filename must be interconversion with its class name. 
     66                # In this class, the conversion is do with +file2klass+/+klass2file+ methods. 
    4667                def load(klass_name) 
    4768                        return if @plugins.include?(klass_name) 
     
    7495                end 
    7596 
     97                # Get instance of +klass_name+ plugin. 
    7698                def [](klass_name) 
    7799                        @plugins[klass_name][:instance] if @plugins.key?(klass_name) 
    78100                end 
    79101                 
     102                # Unload +klass_name 
    80103                def unload(klass_name) 
    81104                        if @plugins.key?(klass_name) 
     
    85108                end 
    86109                 
     110                # Reload +klass_name+ or 
     111                # load unloaded plugins or 
     112                # reload modified plugins. 
     113                # returns [loaded, unloaded] 
    87114                def reload(klass_name=nil) 
    88115                        if klass_name 
     
    107134                end 
    108135                 
     136                # Unload all plugins and reload it. 
    109137                def force_reload 
    110138                        call(:on_unload) 
     
    113141                end 
    114142                 
     143                # Iterates with plugin name and its instance. 
    115144                def each(&block) 
    116145                        @plugins.each do |k,v| 
     
    119148                end 
    120149                 
     150                # Call +name+ method of each plugins with +args+ 
     151                # and returns Hash of the result and its plugin name. 
    121152                def call(name, *args) 
    122153                        ret = {} 
     
    127158                end 
    128159 
     160                # Undefined methods are delegated to each plugins. 
     161                # This is alias of +call+ 
    129162                def method_missing(name, *args) 
    130163                        call(name, *args) 
    131164                end 
    132165 
    133                 # foo/foo_bar => Foo::FooBar 
     166                private 
     167                # convert foo/foo_bar to Foo::FooBar 
    134168                def file2klass(str) 
    135169                        str.split("/").map {|c| 
     
    138172                end 
    139173                 
    140                 # Foo::FooBar => foo/foo_bar  
     174                # convert Foo::FooBar to foo/foo_bar  
    141175                def klass2file(str) 
    142176                        str.split(/::/).map {|c|