Class Index

Quicksearch

Arrow::Configurable

A mixin that adds configurability via an Arrow::Config object.

Attributes

config_key[W]
The symbol which corresponds to the section of the configuration used to configure the Configurable class.
modules[RW]

(Not documented)

Public Class Methods

configure_modules( config, dispatcher ) click to toggle source

Configure Configurable classes with the sections of the specified config that correspond to their config_key, if present. (Undocumented)

     # File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 137
137:         def self::configure_modules( config, dispatcher )
138:             
139:             # Have to keep messages from being logged before logging is 
140:             # configured.
141:             logmessages = []
142:             # logmessages << [
143:             #    :debug, "Propagating config to Configurable classes: %p" %
144:             #    [@modules] ]
145: 
146:             @modules.each do |mod|
147:                 key = mod.config_key
148:                 
149:                 if config.member?( key )
150:                     value = config.send( key )
151:                     logmessages << [
152:                         :debug, 
153:                         "Configuring %s with the %s section of the config: %p" %
154:                             [mod.name, key, value] ]
155: 
156:                     if mod.method(:configure).arity == 2
157:                         mod.configure( value, dispatcher )
158:                     else
159:                         mod.configure( value )
160:                     end
161:                 else
162:                     logmessages << [
163:                         :debug,
164:                         "Skipping %s: no %s section in the config" %
165:                         [mod.name, key] ]
166:                 end
167:             end
168:             
169:             logmessages.each do |lvl, message|
170:                 Arrow::Logger[ self ].send( lvl, message )
171:             end
172: 
173:             Arrow::Logger[ self ].debug "Propagated config to %d modules: %p" %
174:                 [ @modules.length, @modules ]
175:             return @modules
176:         end
extend_object( obj ) click to toggle source

Make the given object (which must be a Module) configurable via a section of an Arrow::Config object.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 112
112:         def self::extend_object( obj )
113:             raise ArgumentError, "can't make a #{obj.class} Configurable" unless
114:                 obj.is_a?( Module )
115: 
116:             super
117:             @modules << obj
118:         end
included( mod ) click to toggle source

Mixin hook: extend including classes

     # File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 128
128:         def self::included( mod )
129:             mod.extend( self )
130:             super
131:         end
make_key_from_classname( klass ) click to toggle source

Generate a config key from the name of the given klass.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 122
122:         def self::make_key_from_classname( klass )
123:             klass.name.sub( /^Arrow::/, '' ).gsub( /\W+/, '_' ).downcase.to_sym
124:         end

Public Instance Methods

config_key( sym=nil ) click to toggle source

Get (and optionally set) the config_key.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 195
195:         def config_key( sym=nil )
196:             @config_key = sym unless sym.nil?
197:             @config_key ||= Arrow::Configurable.make_key_from_classname( self )
198:             @config_key
199:         end
configure( config, dispatcher ) click to toggle source

Default configuration method.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 203
203:         def configure( config, dispatcher )
204:             raise NotImplementedError,
205:                 "#{self.name} does not implement required method 'configure'"
206:         end

secsequence

--- SEC00078

seccomment

--- ""

attributes

--- 
- name: config_key
  rw: W
  a_desc: |+
    
    The symbol which corresponds to the section of the configuration used to <a
    href="Configurable.html#M000048">configure</a> the <a
    href="Configurable.html">Configurable</a> class.
    
- name: modules
  rw: RW
  a_desc: ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000046
    name: configure_modules
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 137</span>\n\
      137:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">configure_modules</span>( <span class=\"ruby-identifier\">config</span>, <span class=\"ruby-identifier\">dispatcher</span> )\n\
      138:             \n\
      139:             <span class=\"ruby-comment cmt\"># Have to keep messages from being logged before logging is </span>\n\
      140:             <span class=\"ruby-comment cmt\"># configured.</span>\n\
      141:             <span class=\"ruby-identifier\">logmessages</span> = []\n\
      142:             <span class=\"ruby-comment cmt\"># logmessages &lt;&lt; [</span>\n\
      143:             <span class=\"ruby-comment cmt\">#    :debug, &quot;Propagating config to Configurable classes: %p&quot; %</span>\n\
      144:             <span class=\"ruby-comment cmt\">#    [@modules] ]</span>\n\
      145: \n\
      146:             <span class=\"ruby-ivar\">@modules</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">mod</span><span class=\"ruby-operator\">|</span>\n\
      147:                 <span class=\"ruby-identifier\">key</span> = <span class=\"ruby-identifier\">mod</span>.<span class=\"ruby-identifier\">config_key</span>\n\
      148:                 \n\
      149:                 <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">config</span>.<span class=\"ruby-identifier\">member?</span>( <span class=\"ruby-identifier\">key</span> )\n\
      150:                     <span class=\"ruby-identifier\">value</span> = <span class=\"ruby-identifier\">config</span>.<span class=\"ruby-identifier\">send</span>( <span class=\"ruby-identifier\">key</span> )\n\
      151:                     <span class=\"ruby-identifier\">logmessages</span> <span class=\"ruby-operator\">&lt;&lt;</span> [\n\
      152:                         <span class=\"ruby-identifier\">:debug</span>, \n\
      153:                         <span class=\"ruby-value str\">&quot;Configuring %s with the %s section of the config: %p&quot;</span> <span class=\"ruby-operator\">%</span>\n\
      154:                             [<span class=\"ruby-identifier\">mod</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">key</span>, <span class=\"ruby-identifier\">value</span>] ]\n\
      155: \n\
      156:                     <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">mod</span>.<span class=\"ruby-identifier\">method</span>(<span class=\"ruby-identifier\">:configure</span>).<span class=\"ruby-identifier\">arity</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">2</span>\n\
      157:                         <span class=\"ruby-identifier\">mod</span>.<span class=\"ruby-identifier\">configure</span>( <span class=\"ruby-identifier\">value</span>, <span class=\"ruby-identifier\">dispatcher</span> )\n\
      158:                     <span class=\"ruby-keyword kw\">else</span>\n\
      159:                         <span class=\"ruby-identifier\">mod</span>.<span class=\"ruby-identifier\">configure</span>( <span class=\"ruby-identifier\">value</span> )\n\
      160:                     <span class=\"ruby-keyword kw\">end</span>\n\
      161:                 <span class=\"ruby-keyword kw\">else</span>\n\
      162:                     <span class=\"ruby-identifier\">logmessages</span> <span class=\"ruby-operator\">&lt;&lt;</span> [\n\
      163:                         <span class=\"ruby-identifier\">:debug</span>,\n\
      164:                         <span class=\"ruby-value str\">&quot;Skipping %s: no %s section in the config&quot;</span> <span class=\"ruby-operator\">%</span>\n\
      165:                         [<span class=\"ruby-identifier\">mod</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">key</span>] ]\n\
      166:                 <span class=\"ruby-keyword kw\">end</span>\n\
      167:             <span class=\"ruby-keyword kw\">end</span>\n\
      168:             \n\
      169:             <span class=\"ruby-identifier\">logmessages</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">lvl</span>, <span class=\"ruby-identifier\">message</span><span class=\"ruby-operator\">|</span>\n\
      170:                 <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[ <span class=\"ruby-keyword kw\">self</span> ].<span class=\"ruby-identifier\">send</span>( <span class=\"ruby-identifier\">lvl</span>, <span class=\"ruby-identifier\">message</span> )\n\
      171:             <span class=\"ruby-keyword kw\">end</span>\n\
      172: \n\
      173:             <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[ <span class=\"ruby-keyword kw\">self</span> ].<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">&quot;Propagated config to %d modules: %p&quot;</span> <span class=\"ruby-operator\">%</span>\n\
      174:                 [ <span class=\"ruby-ivar\">@modules</span>.<span class=\"ruby-identifier\">length</span>, <span class=\"ruby-ivar\">@modules</span> ]\n\
      175:             <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@modules</span>\n\
      176:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Configure <a href="Configurable.html">Configurable</a> classes with the
      sections of the specified <tt>config</tt> that correspond to their <tt><a
      href="Configurable.html#M000047">config_key</a></tt>, if present.
      (Undocumented)
      </p>
    params: ( config, dispatcher )
  - visibility: public
    aref: M000043
    name: extend_object
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 112</span>\n\
      112:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">extend_object</span>( <span class=\"ruby-identifier\">obj</span> )\n\
      113:             <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-node\">&quot;can't make a #{obj.class} Configurable&quot;</span> <span class=\"ruby-keyword kw\">unless</span>\n\
      114:                 <span class=\"ruby-identifier\">obj</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">Module</span> )\n\
      115: \n\
      116:             <span class=\"ruby-keyword kw\">super</span>\n\
      117:             <span class=\"ruby-ivar\">@modules</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">obj</span>\n\
      118:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Make the given object (which must be a <a href="../Module.html">Module</a>)
      configurable via a section of an <a href="Config.html">Arrow::Config</a>
      object.
      </p>
    params: ( obj )
  - visibility: public
    aref: M000045
    name: included
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 128</span>\n\
      128:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">included</span>( <span class=\"ruby-identifier\">mod</span> )\n\
      129:             <span class=\"ruby-identifier\">mod</span>.<span class=\"ruby-identifier\">extend</span>( <span class=\"ruby-keyword kw\">self</span> )\n\
      130:             <span class=\"ruby-keyword kw\">super</span>\n\
      131:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Mixin hook: extend including classes
      </p>
    params: ( mod )
  - visibility: public
    aref: M000044
    name: make_key_from_classname
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 122</span>\n\
      122:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">make_key_from_classname</span>( <span class=\"ruby-identifier\">klass</span> )\n\
      123:             <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">name</span>.<span class=\"ruby-identifier\">sub</span>( <span class=\"ruby-regexp re\">/^Arrow::/</span>, <span class=\"ruby-value str\">''</span> ).<span class=\"ruby-identifier\">gsub</span>( <span class=\"ruby-regexp re\">/\\W+/</span>, <span class=\"ruby-value str\">'_'</span> ).<span class=\"ruby-identifier\">downcase</span>.<span class=\"ruby-identifier\">to_sym</span>\n\
      124:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Generate a config key from the name of the given <tt>klass</tt>.
      </p>
    params: ( klass )
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000047
    name: config_key
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 195</span>\n\
      195:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">config_key</span>( <span class=\"ruby-identifier\">sym</span>=<span class=\"ruby-keyword kw\">nil</span> )\n\
      196:             <span class=\"ruby-ivar\">@config_key</span> = <span class=\"ruby-identifier\">sym</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">sym</span>.<span class=\"ruby-identifier\">nil?</span>\n\
      197:             <span class=\"ruby-ivar\">@config_key</span> <span class=\"ruby-operator\">||=</span> <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Configurable</span>.<span class=\"ruby-identifier\">make_key_from_classname</span>( <span class=\"ruby-keyword kw\">self</span> )\n\
      198:             <span class=\"ruby-ivar\">@config_key</span>\n\
      199:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Get (and optionally set) the <tt><a
      href="Configurable.html#M000047">config_key</a></tt>.
      </p>
    params: ( sym=nil )
  - visibility: public
    aref: M000048
    name: configure
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/mixins.rb, line 203</span>\n\
      203:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">configure</span>( <span class=\"ruby-identifier\">config</span>, <span class=\"ruby-identifier\">dispatcher</span> )\n\
      204:             <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NotImplementedError</span>,\n\
      205:                 <span class=\"ruby-node\">&quot;#{self.name} does not implement required method 'configure'&quot;</span>\n\
      206:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Default configuration method.
      </p>
    params: ( config, dispatcher )
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.