Class: Container
- Inherits:
-
Object
- Object
- Container
- Defined in:
- lib/geoff/container.rb
Instance Attribute Summary collapse
-
#children_dsls ⇒ Object
readonly
Returns the value of attribute children_dsls.
-
#node_dsls ⇒ Object
readonly
Returns the value of attribute node_dsls.
Instance Method Summary collapse
-
#initialize(dsls = {}) ⇒ Container
constructor
A new instance of Container.
- #merge(other) ⇒ Object
- #method_missing(m, *args, &blk) ⇒ Object
- #set_recipient_of_node_dsl(children_dsl) ⇒ Object
Constructor Details
#initialize(dsls = {}) ⇒ Container
Returns a new instance of Container.
4 5 6 7 |
# File 'lib/geoff/container.rb', line 4 def initialize dsls = {} @node_dsls = dsls[:node_dsls ] || {} @children_dsls = dsls[:children_dsls] || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &blk) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/geoff/container.rb', line 14 def method_missing m, *args, &blk if m.to_s.last == "=" # assignment node_or_children_dsl = args.first # We should only have one dsls hash storing both node dsls and children # dsls and methods handle_node_dsl and handle_children_dsl should be # moved to corresponding classes. if node_or_children_dsl.is_a? NodeDsl @node_dsls[m.to_s[0..-2].to_sym] = args.first else @children_dsls[m.to_s[0..-2].to_sym] = args.first end elsif @node_dsls.has_key?(m) handle_node_dsl m, *args elsif @children_dsls.has_key?(m) handle_children_dsl m, *args else raise Geoff::ContainerLabelMissing, "Container has no key #{m}" end end |
Instance Attribute Details
#children_dsls ⇒ Object (readonly)
Returns the value of attribute children_dsls.
2 3 4 |
# File 'lib/geoff/container.rb', line 2 def children_dsls @children_dsls end |
#node_dsls ⇒ Object (readonly)
Returns the value of attribute node_dsls.
2 3 4 |
# File 'lib/geoff/container.rb', line 2 def node_dsls @node_dsls end |
Instance Method Details
#merge(other) ⇒ Object
9 10 11 12 |
# File 'lib/geoff/container.rb', line 9 def merge other @node_dsls .merge! other.node_dsls @children_dsls.merge! other.children_dsls end |
#set_recipient_of_node_dsl(children_dsl) ⇒ Object
38 39 40 |
# File 'lib/geoff/container.rb', line 38 def set_recipient_of_node_dsl children_dsl @recipient = children_dsl end |