class DTK::DSL::Template::V1::Component

Public Class Methods

elements_collection_type() click to toggle source
# File lib/dsl/template/v1/component.rb, line 43
def self.elements_collection_type
  :array
end
generate_elements(components_content, parent) click to toggle source

For generation

# File lib/dsl/template/v1/component.rb, line 66
def self.generate_elements(components_content, parent)
  components_content.map do |name, component|
    if component_hash = generate_element?(component, parent)
      component_hash.empty? ? name : { name => component_hash }
    end
  end.compact
end
parse_elements(input_array, parent_info) click to toggle source
# File lib/dsl/template/v1/component.rb, line 47
def self.parse_elements(input_array, parent_info)
  input_array.inject(file_parser_output_hash) do |h, component|
    name = name(component, :parent => parent_info.parent)
    h.merge(name => parse_element(component, parent_info, :index => name))
  end
end

Private Class Methods

name(input, opts = {}) click to toggle source

opts can have keys:

:parent
:this

Will not have both keys

# File lib/dsl/template/v1/component.rb, line 97
def self.name(input, opts = {})
  if input.kind_of?(::String)
    input
  elsif input.kind_of?(::Hash) and input.size > 0
    input.keys.first
  else
    raise (opts[:this] || opts[:parent]).parsing_error([:WrongObjectType, input, [::String, ::Hash]])
  end
end

Public Instance Methods

generate!() click to toggle source
# File lib/dsl/template/v1/component.rb, line 74
def generate!
  merge(generate_component_hash)
end
generate_yaml_object?() click to toggle source

Ovewritting this function because dont want to return nil when empty content

# File lib/dsl/template/v1/component.rb, line 79
def generate_yaml_object?
  generate! unless skip_for_generation?
end
parse!() click to toggle source
# File lib/dsl/template/v1/component.rb, line 54
def parse!
  # TODO: This is a catchall that removes ones we so far are parsing and then has catch all
  if input_string?
    parse_when_string!
  elsif input_hash = input_hash?
    parse_when_hash!
  else
    raise parsing_error(:WrongObjectType, @input, [::String, ::Hash])
  end
end
parser_output_type() click to toggle source

For parsing

# File lib/dsl/template/v1/component.rb, line 39
def parser_output_type 
  :hash
end

Private Instance Methods

generate_component_hash() click to toggle source
# File lib/dsl/template/v1/component.rb, line 85
def generate_component_hash
  ret = {}
  set_generation_hash(ret, :Attributes, generate_child_elements(:attribute, val(:Attributes)))
  set_generation_hash(ret, :Links, generate_child_elements(:component_link, val(:ComponentLinks)))
  set_generation_hash(ret, :Components, generate_child_elements(:component, val(:Components)))
  ret
end
name() click to toggle source
# File lib/dsl/template/v1/component.rb, line 107
def name
  self.class.name(@input, :this => self)
end
parse_set_property_value_and_remove!(properties, constant, opts = {}) click to toggle source

opts can have keys:

:matching_key_value
# File lib/dsl/template/v1/component.rb, line 130
def parse_set_property_value_and_remove!(properties, constant, opts = {})
  if matching_key_value = opts[:matching_key_value] || constant_class.matching_key_and_value?(properties, constant)
    key_in_properties   = matching_key_value.keys.first
    value               = matching_key_value.values.first
    canonical_key       = constant_class.canonical_value(constant) # this is string
    parse_template_type = canonical_key.sub(/s$/, '').to_sym

    # example what below looks like set? :Components, parse_child_elements?(:component, :Components, :input_hash => { 'components' => components})
    set? constant, parse_child_elements?(parse_template_type, constant, :input_hash => { canonical_key => value })
    properties.delete(key_in_properties)
  end
end
parse_when_hash!() click to toggle source
# File lib/dsl/template/v1/component.rb, line 114
def parse_when_hash!
  unless input_hash.size == 1 and input_hash.values.first.kind_of?(::Hash)
    raise parsing_error("Component is ill-formed; it must be string or hash")
  end

  properties = input_hash.values.first

  # removes from peroperties so we can simply merge keys not processed
  parse_set_property_value_and_remove!(properties, :Attributes)
  parse_set_property_value_and_remove__component_links!(properties)
  parse_set_property_value_and_remove!(properties, :Components)
  merge properties unless properties.empty?
end
parse_when_string!() click to toggle source
# File lib/dsl/template/v1/component.rb, line 111
def parse_when_string!
end