class Container attr_reader :node_dsls, :children_dsls def initialize dsls = {} @node_dsls = dsls[:node_dsls ] || {} @children_dsls = dsls[:children_dsls] || {} end def merge other @node_dsls .merge! other.node_dsls @children_dsls.merge! other.children_dsls end 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 def set_recipient_of_node_dsl children_dsl @recipient = children_dsl end private def handle_node_dsl m, *args node_dsl = @node_dsls[m] rel_properties = args.first || {} if rel_properties[:clone] node_dsl = node_dsl.clone rel_properties.delete(:clone) end @recipient.add_node_dsl node_dsl, rel_properties node_dsl end def handle_children_dsl m, *args children_dsl = @children_dsls[m] rel_properties_override = args.first || {} children_dsl.node_dsls.each do |node_dsl, rel_properties| @recipient.add_node_dsl node_dsl.clone, rel_properties.merge(rel_properties_override) end children_dsl end end