Class: DTK::DSL::Template::V1::Component

Inherits:
DTK::DSL::Template::V1 show all
Defined in:
lib/dsl/template/v1/component.rb,
lib/dsl/template/v1/component/semantic_parse.rb

Defined Under Namespace

Modules: Constant Classes: SemanticParse

Constant Summary

Constants inherited from DTK::DSL::Template::V1

VERSION

Instance Attribute Summary

Attributes included from NestedDSLFile::Mixin

#nested_file_content

Attributes included from Generation::Mixin

#filter, #top

Attributes included from Parsing::Mixin

#file_obj, #parent_key

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DTK::DSL::Template::V1

#dsl_version, #template_version

Methods inherited from DTK::DSL::Template

#add, create_for_generation, create_for_parsing, #initialize, #merge, #req, #set, #set?, #val

Methods included from Parsing::ClassMixin

#elements_collection_type, #file_parser_output_array, #file_parser_output_hash, #parse_element, #parse_elements

Methods included from Generation::ClassMixin

#generate_elements

Methods included from Generation::Mixin

#generate?, #generate_yaml_file_path__content_array, #generate_yaml_object, #generate_yaml_text, #yaml_object_type

Methods included from Parsing::Mixin

#parse, #parsing_error

Constructor Details

This class inherits a constructor from DTK::DSL::Template

Class Method Details

.elements_collection_typeObject



39
40
41
# File 'lib/dsl/template/v1/component.rb', line 39

def self.elements_collection_type
  :array
end

.generate_elements(components_content, parent) ⇒ Object

For generation



62
63
64
65
66
67
68
# File 'lib/dsl/template/v1/component.rb', line 62

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) ⇒ Object



43
44
45
46
47
48
# File 'lib/dsl/template/v1/component.rb', line 43

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

Instance Method Details

#generate!Object



70
71
72
# File 'lib/dsl/template/v1/component.rb', line 70

def generate!
  merge(generate_component_hash)
end

#generate_yaml_object?Boolean

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

Returns:

  • (Boolean)


75
76
77
# File 'lib/dsl/template/v1/component.rb', line 75

def generate_yaml_object?
  generate! unless skip_for_generation?
end

#parse!Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/dsl/template/v1/component.rb', line 50

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_typeObject

For parsing



35
36
37
# File 'lib/dsl/template/v1/component.rb', line 35

def parser_output_type 
  :hash
end