Hash-wrapper that allows struct-like accessor calls on nested hashes.
Create a new ConfigStruct from the given hash.
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 445
445: def initialize( hash )
446: @hash = hash.dup
447: @dirty = false
448: end
Call into the given block for each member of the receiver.
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 514
514: def each( &block ) # :yield: member, value
515: @hash.each( &block )
516: end
Returns true if the given name is the name of a member of the receiver.
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 508
508: def member?( name )
509: return @hash.key?( name.to_s.intern )
510: end
Return a new ConfigStruct which is the result of merging the receiver with the given other object (a Hash or another ConfigStruct).
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 552
552: def merge( other )
553: self.dup.merge!( other )
554: end
Merge the specified other object with this config struct. The other object can be either a Hash, another ConfigStruct, or an Arrow::Config.
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 523
523: def merge!( other )
524: case other
525: when Hash
526: @hash = self.to_h.merge( other,
527: &Arrow::HashMergeFunction )
528:
529: when ConfigStruct
530: @hash = self.to_h.merge( other.to_h,
531: &Arrow::HashMergeFunction )
532:
533: when Arrow::Config
534: @hash = self.to_h.merge( other.struct.to_h,
535: &Arrow::HashMergeFunction )
536:
537: else
538: raise TypeError,
539: "Don't know how to merge with a %p" % other.class
540: end
541:
542: # :TODO: Actually check to see if anything has changed?
543: @dirty = true
544:
545: return self
546: end
Returns true if the ConfigStruct or any of its sub-structs have changed since it was created.
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 462
462: def modified?
463: @dirty || @hash.values.find do |obj|
464: obj.is_a?( ConfigStruct ) && obj.modified?
465: end
466: end
Return true if the receiver responds to the given method. Overridden to grok autoloaded methods.
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 493
493: def respond_to?( sym, priv=false )
494: key = sym.to_s.sub( /(=|\?)$/, '' ).intern
495: return true if @hash.key?( key )
496: super
497: end
Return the receiver‘s values as a (possibly multi-dimensional) Hash with String keys.
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 471
471: def to_hash
472: rhash = {}
473: @hash.each {|k,v|
474: case v
475: when ConfigStruct
476: rhash[k] = v.to_h
477: when NilClass, FalseClass, TrueClass, Numeric
478: # No-op (can't dup)
479: rhash[k] = v
480: when Symbol
481: rhash[k] = v.to_s
482: else
483: rhash[k] = v.dup
484: end
485: }
486: return rhash
487: end
Handle calls to key-methods
# File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 562
562: def method_missing( sym, *args )
563: key = sym.to_s.sub( /(=|\?)$/, '' ).intern
564: return nil unless @hash.key?( key )
565:
566: self.class.class_eval {
567: define_method( key ) {
568: if @hash[ key ].is_a?( Hash )
569: @hash[ key ] = ConfigStruct.new( @hash[key] )
570: end
571:
572: @hash[ key ]
573: }
574: define_method( "#{key}?" ) {@hash[key] ? true : false}
575: define_method( "#{key}=" ) {|val|
576: @dirty = @hash[key] != val
577: @hash[key] = val
578: }
579: }
580:
581: self.__send__( sym, *args )
582: end
--- SEC00033
--- ""
---
- name: modified
rw: W
a_desc: |+
Modification flag. Set to <tt>true</tt> to indicate the contents of the
Struct have changed since it was created.
---
- methods:
- visibility: public
aref: M000291
name: new
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 445</span>\n\
445: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">hash</span> )\n\
446: <span class=\"ruby-ivar\">@hash</span> = <span class=\"ruby-identifier\">hash</span>.<span class=\"ruby-identifier\">dup</span>\n\
447: <span class=\"ruby-ivar\">@dirty</span> = <span class=\"ruby-keyword kw\">false</span>\n\
448: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Create a <a href="ConfigStruct.html#M000291">new</a> <a
href="ConfigStruct.html">ConfigStruct</a> from the given <tt>hash</tt>.
</p>
params: ( hash )
category: Class
type: Public
- methods:
- visibility: public
aref: M000298
name: each
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 514</span>\n\
514: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">each</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> ) <span class=\"ruby-comment cmt\"># :yield: member, value</span>\n\
515: <span class=\"ruby-ivar\">@hash</span>.<span class=\"ruby-identifier\">each</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
516: <span class=\"ruby-keyword kw\">end</span>"
aka:
- aref: ConfigStruct.html#M000299
name: each_section
m_desc: |-
<p>
Call into the given block for <a href="ConfigStruct.html#M000298">each</a>
member of the receiver.
</p>
params: ( ) {|member, value| ...}
- visibility: public
aref: M000299
name: each_section
m_desc: |-
<p>
Alias for <a href="ConfigStruct.html#M000298">#each</a>
</p>
params: ( )
- visibility: public
aref: M000297
name: member?
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 508</span>\n\
508: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">member?</span>( <span class=\"ruby-identifier\">name</span> )\n\
509: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@hash</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">name</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">intern</span> )\n\
510: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns <tt>true</tt> if the given <tt>name</tt> is the name of a member of
the receiver.
</p>
params: ( name )
- visibility: public
aref: M000296
name: members
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 501</span>\n\
501: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">members</span>\n\
502: <span class=\"ruby-ivar\">@hash</span>.<span class=\"ruby-identifier\">keys</span>\n\
503: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns an Array of Symbols, on for <a
href="ConfigStruct.html#M000298">each</a> of the struct‘s <a
href="ConfigStruct.html#M000296">members</a>.
</p>
params: ()
- visibility: public
aref: M000301
name: merge
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 552</span>\n\
552: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">merge</span>( <span class=\"ruby-identifier\">other</span> )\n\
553: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">dup</span>.<span class=\"ruby-identifier\">merge!</span>( <span class=\"ruby-identifier\">other</span> )\n\
554: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return a <a href="ConfigStruct.html#M000291">new</a> <a
href="ConfigStruct.html">ConfigStruct</a> which is the result of merging
the receiver with the given <tt>other</tt> object (a Hash or another <a
href="ConfigStruct.html">ConfigStruct</a>).
</p>
params: ( other )
- visibility: public
aref: M000300
name: merge!
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 523</span>\n\
523: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">merge!</span>( <span class=\"ruby-identifier\">other</span> )\n\
524: <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">other</span>\n\
525: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Hash</span>\n\
526: <span class=\"ruby-ivar\">@hash</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">to_h</span>.<span class=\"ruby-identifier\">merge</span>( <span class=\"ruby-identifier\">other</span>,\n\
527: <span class=\"ruby-operator\">&</span><span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">HashMergeFunction</span> )\n\
528: \n\
529: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">ConfigStruct</span>\n\
530: <span class=\"ruby-ivar\">@hash</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">to_h</span>.<span class=\"ruby-identifier\">merge</span>( <span class=\"ruby-identifier\">other</span>.<span class=\"ruby-identifier\">to_h</span>,\n\
531: <span class=\"ruby-operator\">&</span><span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">HashMergeFunction</span> )\n\
532: \n\
533: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Config</span>\n\
534: <span class=\"ruby-ivar\">@hash</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">to_h</span>.<span class=\"ruby-identifier\">merge</span>( <span class=\"ruby-identifier\">other</span>.<span class=\"ruby-identifier\">struct</span>.<span class=\"ruby-identifier\">to_h</span>,\n\
535: <span class=\"ruby-operator\">&</span><span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">HashMergeFunction</span> )\n\
536: \n\
537: <span class=\"ruby-keyword kw\">else</span>\n\
538: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">TypeError</span>,\n\
539: <span class=\"ruby-value str\">"Don't know how to merge with a %p"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">other</span>.<span class=\"ruby-identifier\">class</span>\n\
540: <span class=\"ruby-keyword kw\">end</span>\n\
541: \n\
542: <span class=\"ruby-comment cmt\"># :TODO: Actually check to see if anything has changed?</span>\n\
543: <span class=\"ruby-ivar\">@dirty</span> = <span class=\"ruby-keyword kw\">true</span>\n\
544: \n\
545: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">self</span>\n\
546: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Merge the specified <tt>other</tt> object with this config struct. The
<tt>other</tt> object can be either a Hash, another <a
href="ConfigStruct.html">ConfigStruct</a>, or an <a
href="../Config.html">Arrow::Config</a>.
</p>
params: ( other )
- visibility: public
aref: M000292
name: modified?
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 462</span>\n\
462: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">modified?</span>\n\
463: <span class=\"ruby-ivar\">@dirty</span> <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@hash</span>.<span class=\"ruby-identifier\">values</span>.<span class=\"ruby-identifier\">find</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">obj</span><span class=\"ruby-operator\">|</span>\n\
464: <span class=\"ruby-identifier\">obj</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">ConfigStruct</span> ) <span class=\"ruby-operator\">&&</span> <span class=\"ruby-identifier\">obj</span>.<span class=\"ruby-identifier\">modified?</span>\n\
465: <span class=\"ruby-keyword kw\">end</span>\n\
466: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns <tt>true</tt> if the <a href="ConfigStruct.html">ConfigStruct</a>
or any of its sub-structs have changed since it was created.
</p>
params: ()
- visibility: public
aref: M000295
name: respond_to?
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 493</span>\n\
493: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">respond_to?</span>( <span class=\"ruby-identifier\">sym</span>, <span class=\"ruby-identifier\">priv</span>=<span class=\"ruby-keyword kw\">false</span> )\n\
494: <span class=\"ruby-identifier\">key</span> = <span class=\"ruby-identifier\">sym</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">sub</span>( <span class=\"ruby-regexp re\">/(=|\\?)$/</span>, <span class=\"ruby-value str\">''</span> ).<span class=\"ruby-identifier\">intern</span>\n\
495: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">true</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@hash</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">key</span> )\n\
496: <span class=\"ruby-keyword kw\">super</span>\n\
497: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return <tt>true</tt> if the receiver responds to the given method.
Overridden to grok autoloaded methods.
</p>
params: ( sym, priv=false )
- visibility: public
aref: M000294
name: to_h
m_desc: |-
<p>
Alias for <a href="ConfigStruct.html#M000293">#to_hash</a>
</p>
params: ()
- visibility: public
aref: M000293
name: to_hash
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 471</span>\n\
471: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">to_hash</span>\n\
472: <span class=\"ruby-identifier\">rhash</span> = {}\n\
473: <span class=\"ruby-ivar\">@hash</span>.<span class=\"ruby-identifier\">each</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">k</span>,<span class=\"ruby-identifier\">v</span><span class=\"ruby-operator\">|</span>\n\
474: <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">v</span>\n\
475: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">ConfigStruct</span>\n\
476: <span class=\"ruby-identifier\">rhash</span>[<span class=\"ruby-identifier\">k</span>] = <span class=\"ruby-identifier\">v</span>.<span class=\"ruby-identifier\">to_h</span>\n\
477: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">NilClass</span>, <span class=\"ruby-constant\">FalseClass</span>, <span class=\"ruby-constant\">TrueClass</span>, <span class=\"ruby-constant\">Numeric</span>\n\
478: <span class=\"ruby-comment cmt\"># No-op (can't dup)</span>\n\
479: <span class=\"ruby-identifier\">rhash</span>[<span class=\"ruby-identifier\">k</span>] = <span class=\"ruby-identifier\">v</span>\n\
480: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Symbol</span>\n\
481: <span class=\"ruby-identifier\">rhash</span>[<span class=\"ruby-identifier\">k</span>] = <span class=\"ruby-identifier\">v</span>.<span class=\"ruby-identifier\">to_s</span>\n\
482: <span class=\"ruby-keyword kw\">else</span>\n\
483: <span class=\"ruby-identifier\">rhash</span>[<span class=\"ruby-identifier\">k</span>] = <span class=\"ruby-identifier\">v</span>.<span class=\"ruby-identifier\">dup</span>\n\
484: <span class=\"ruby-keyword kw\">end</span>\n\
485: }\n\
486: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">rhash</span>\n\
487: <span class=\"ruby-keyword kw\">end</span>"
aka:
- aref: ConfigStruct.html#M000294
name: to_h
m_desc: |-
<p>
Return the receiver‘s values as a (possibly multi-dimensional) Hash
with String keys.
</p>
params: ()
category: Instance
type: Public
- methods:
- visibility: protected
aref: M000302
name: method_missing
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/config.rb, line 562</span>\n\
562: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">method_missing</span>( <span class=\"ruby-identifier\">sym</span>, <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">args</span> )\n\
563: <span class=\"ruby-identifier\">key</span> = <span class=\"ruby-identifier\">sym</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">sub</span>( <span class=\"ruby-regexp re\">/(=|\\?)$/</span>, <span class=\"ruby-value str\">''</span> ).<span class=\"ruby-identifier\">intern</span>\n\
564: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@hash</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">key</span> )\n\
565: \n\
566: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">class_eval</span> {\n\
567: <span class=\"ruby-identifier\">define_method</span>( <span class=\"ruby-identifier\">key</span> ) {\n\
568: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@hash</span>[ <span class=\"ruby-identifier\">key</span> ].<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">Hash</span> )\n\
569: <span class=\"ruby-ivar\">@hash</span>[ <span class=\"ruby-identifier\">key</span> ] = <span class=\"ruby-constant\">ConfigStruct</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-ivar\">@hash</span>[<span class=\"ruby-identifier\">key</span>] )\n\
570: <span class=\"ruby-keyword kw\">end</span>\n\
571: \n\
572: <span class=\"ruby-ivar\">@hash</span>[ <span class=\"ruby-identifier\">key</span> ]\n\
573: }\n\
574: <span class=\"ruby-identifier\">define_method</span>( <span class=\"ruby-node\">"#{key}?"</span> ) {<span class=\"ruby-ivar\">@hash</span>[<span class=\"ruby-identifier\">key</span>] <span class=\"ruby-operator\">?</span> <span class=\"ruby-keyword kw\">true</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">false</span>}\n\
575: <span class=\"ruby-identifier\">define_method</span>( <span class=\"ruby-node\">"#{key}="</span> ) {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">val</span><span class=\"ruby-operator\">|</span>\n\
576: <span class=\"ruby-ivar\">@dirty</span> = <span class=\"ruby-ivar\">@hash</span>[<span class=\"ruby-identifier\">key</span>] <span class=\"ruby-operator\">!=</span> <span class=\"ruby-identifier\">val</span>\n\
577: <span class=\"ruby-ivar\">@hash</span>[<span class=\"ruby-identifier\">key</span>] = <span class=\"ruby-identifier\">val</span>\n\
578: }\n\
579: }\n\
580: \n\
581: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">__send__</span>( <span class=\"ruby-identifier\">sym</span>, <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">args</span> )\n\
582: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Handle calls to key-methods
</p>
params: ( sym, *args )
category: Instance
type: Protected
---
Generated with the Darkfish Rdoc Generator.