Class: PMP::Links
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- PMP::Links
- Includes:
- Utils
- Defined in:
- lib/pmp/links.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #[]=(k, link) ⇒ Object
- #add_link_name(name) ⇒ Object
-
#initialize(parent) ⇒ Links
constructor
A new instance of Links.
- #set_parent(link) ⇒ Object
Methods included from Utils
#to_json_key_name, #to_ruby_safe_name
Constructor Details
#initialize(parent) ⇒ Links
Returns a new instance of Links.
10 11 12 13 |
# File 'lib/pmp/links.rb', line 10 def initialize(parent) super() self.parent = parent end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/pmp/links.rb', line 8 def parent @parent end |
Instance Method Details
#[]=(k, link) ⇒ Object
15 16 17 18 19 |
# File 'lib/pmp/links.rb', line 15 def []=(k, link) super set_parent(link) add_link_name(k) end |
#add_link_name(name) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/pmp/links.rb', line 21 def add_link_name(name) name = name.to_sym unless parent.respond_to?(name) parent.define_singleton_method(name) { self.links[name] } parent.define_singleton_method("#{name}=") { |x| puts "setter: #{self.inspect}"; self.links[name] = x } end end |
#set_parent(link) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/pmp/links.rb', line 29 def set_parent(link) if link.respond_to?(:parent) link.parent = self.parent elsif link.is_a?(Hash) link.values.each{|l| set_parent(l)} elsif link.is_a?(Enumerable) link.each{|l| set_parent(l)} end end |