module DTK::DSL::Template::Generation::Mixin

Attributes

filter[R]
top[R]

Public Instance Methods

generate!() click to toggle source

Main template-specific generate call; Concrete classes overwrite this

# File lib/dsl/template/generation/mixin.rb, line 23
def generate!
  raise Error::NoMethodForConcreteClass.new(self.class)
end
generate?() click to toggle source

This is overwritten if template can conditionally generate elements

# File lib/dsl/template/generation/mixin.rb, line 28
def generate?
  generate!
end
generate_yaml_file_path__content_array(top_file_path) click to toggle source

Array where each element has keys :path and :content

# File lib/dsl/template/generation/mixin.rb, line 67
def generate_yaml_file_path__content_array(top_file_path)
  self.generate!
  [{ :path => top_file_path, :content => YamlHelper.generate(@yaml_object) }] + generate_nested_dsl_file_path__content_array
end
generate_yaml_object() click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 56
def generate_yaml_object
  generate!
  @yaml_object
end
generate_yaml_object?() click to toggle source

generate_yaml_object? can be ovewritten

# File lib/dsl/template/generation/mixin.rb, line 51
def generate_yaml_object?
  generate?
  is_empty?(@yaml_object) ? nil : @yaml_object
end
generate_yaml_text() click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 61
def generate_yaml_text
  self.generate!
  YamlHelper.generate(@yaml_object)
end
yaml_object_type() click to toggle source

The methods yaml_object_type can be set on concrete class; it wil be set if input and output types are different

# File lib/dsl/template/generation/mixin.rb, line 74
def yaml_object_type
  nil
end

Private Instance Methods

empty_yaml_object(opts = {}) click to toggle source

opts can have keys

:content_input
:output_type
# File lib/dsl/template/generation/mixin.rb, line 97
def empty_yaml_object(opts = {})
  if output_type = opts[:output_type] || self.yaml_object_type
    FileGenerator::YamlObject.create(:output_type => output_type)
  elsif content_input = opts[:content_input]
    FileGenerator::YamlObject.create(:input => content_input)
  else
    raise Error, "If opts[:content_input] is nil, self.yaml_object_type or opts[:output_type] must have a value" 
  end
end
generate_child(parse_template_type, content) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 80
def generate_child(parse_template_type, content)
  if content.nil?
    nil
  else
    template_class(parse_template_type).create_for_generation(content, :filter => @filter, :top => @top).generate_yaml_object
  end
end
generate_child_elements(parse_template_type, content_elements) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 88
def generate_child_elements(parse_template_type, content_elements)
  unless content_elements.nil?
    template_class(parse_template_type).generate_elements(content_elements, self)
  end
end
generation_add(array_element) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 137
def generation_add(array_element)
  select_yaml_object_or_nested_dsl_file << array_element
end
generation_initialize(opts = {}) click to toggle source

opts can have keys

:content (required)
:filter
:top
# File lib/dsl/template/generation/mixin.rb, line 38
def generation_initialize(opts = {})
  unless content = opts[:content]
    raise Error, "Unexpected that opts[:content] is nil"
  end
  @content     = content
  @filter      = opts[:filter]
  @yaml_object = empty_yaml_object(content_input: content)
  @top         = opts[:top] || self
  generation_initialize_nested_dsl_files
end
generation_merge(hash) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 133
def generation_merge(hash)
  select_yaml_object_or_nested_dsl_file.merge!(hash)
end
generation_req(key) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 121
def generation_req(key)
  @content.req(key)
end
generation_set(constant, val) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 129
def generation_set(constant, val)
  set_generation_hash(select_yaml_object_or_nested_dsl_file, constant, val)
end
generation_set_scalar(scalar) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 141
def generation_set_scalar(scalar)
  @yaml_object = scalar
end
generation_val(key) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 117
def generation_val(key)
  @content.val(key)
end
is_empty?(obj) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 113
def is_empty?(obj)
  obj.respond_to?(:empty?) and obj.empty?
end
set_generation_hash(hash, constant, val) click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 107
def set_generation_hash(hash, constant, val)
  unless val.nil? or is_empty?(val)
    hash[canonical_key(constant)] = val
  end
end
skip_for_generation?() click to toggle source
# File lib/dsl/template/generation/mixin.rb, line 125
def skip_for_generation?
  @content.skip_for_generation?
end