Module: Treetop_Configgy::Section3

Defined in:
lib/treetop/configgy.rb

Instance Method Summary collapse

Instance Method Details

#apply(config_map, parser) ⇒ Object



1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
# File 'lib/treetop/configgy.rb', line 1315

def apply(config_map, parser)
  new_name = identifier_token.text_value
  nested_config_map = Configgy::ConfigMap.new(config_map.root, config_map.name == "" ? new_name : config_map.name + "." + new_name)
  if attribute_list.elements
    attribute_list.attributes.elements.map { |e| e.tag_attribute }.each do |attr|
      case attr.name.text_value
      when "inherit"
        v = attr.value.to_value
        if config_map[v].instance_of?(Configgy::ConfigMap)
          nested_config_map.inherit_from = config_map[v]
        elsif config_map.root
          config_map.root[v] = Configgy::ConfigMap.new(config_map.root, v) unless config_map.root.has_key?(v)
          if config_map.root[v].instance_of?(Configgy::ConfigMap)
            nested_config_map.inherit_from = config_map.root[v]
          else
            raise ConfigException("can only inherit from blocks")
          end
        end
      end
    end
  end
  config_map[new_name] = nested_config_map
  root.apply(nested_config_map, parser)
end