Class: DTK::DSL::Template

Inherits:
Object
  • Object
show all
Extended by:
Generation::ClassMixin, Parsing::ClassMixin
Includes:
Generation::Mixin, NestedDSLFile::Mixin, Parsing::Mixin
Defined in:
lib/dsl/template/v1/node.rb,
lib/dsl/template.rb,
lib/dsl/template/v1.rb,
lib/dsl/template/loader.rb,
lib/dsl/template/parsing.rb,
lib/dsl/template/generation.rb,
lib/dsl/template/v1/assembly.rb,
lib/dsl/template/v1/workflow.rb,
lib/dsl/template/v1/attribute.rb,
lib/dsl/template/v1/component.rb,
lib/dsl/template/parsing/mixin.rb,
lib/dsl/template/v1/dependency.rb,
lib/dsl/template/v1/module_ref.rb,
lib/dsl/template/nested_dsl_file.rb,
lib/dsl/template/generation/mixin.rb,
lib/dsl/template/v1/common_module.rb,
lib/dsl/template/v1/component_def.rb,
lib/dsl/template/v1/component_link.rb,
lib/dsl/template/v1/node_attribute.rb,
lib/dsl/template/parsing/parent_key.rb,
lib/dsl/template/parsing/class_mixin.rb,
lib/dsl/template/v1/service_instance.rb,
lib/dsl/template/constant_class_mixin.rb,
lib/dsl/template/nested_dsl_file/mixin.rb,
lib/dsl/template/parsing/parsing_error.rb,
lib/dsl/template/generation/class_mixin.rb,
lib/dsl/template/v1/common_module_summary.rb,
lib/dsl/template/v1/service_module_summary.rb,
lib/dsl/template/parsing/parsing_error/subclasses.rb

Overview

Copyright © 2010-2016 dtk contributors

This file is part of the dtk project.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Direct Known Subclasses

V1

Defined Under Namespace

Modules: ClassMixin, Generation, NestedDSLFile, Parsing Classes: Loader, V1

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 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?, #generate_yaml_file_path__content_array, #generate_yaml_object, #generate_yaml_object?, #generate_yaml_text, #yaml_object_type

Methods included from Parsing::Mixin

#parse, #parser_output_type, #parsing_error

Constructor Details

#initialize(type, opts = {}) ⇒ Template

Returns a new instance of Template.



47
48
49
50
51
52
53
# File 'lib/dsl/template.rb', line 47

def initialize(type, opts = {})
  case @type = type
  when :parsing then parsing_initialize(opts)
  when :generation then generation_initialize(opts)
  else raise Error, "Illegal type '#{type}'"
  end
end

Class Method Details

.create_for_generation(content, opts = {}) ⇒ Object

Content is of type InputOutput::Canonical Array or Hash opts can have keys

:filter


43
44
45
# File 'lib/dsl/template.rb', line 43

def self.create_for_generation(content, opts = {})
  new(:generation, opts.merge(:content => content))
end

.create_for_parsing(raw_input, opts = {}) ⇒ Object

opts can have keys

:file_obj
:parent_key


36
37
38
# File 'lib/dsl/template.rb', line 36

def self.create_for_parsing(raw_input, opts = {})
  new(:parsing, opts.merge(:raw_input => raw_input))
end

Instance Method Details

#add(array_element) ⇒ Object



87
88
89
90
91
92
# File 'lib/dsl/template.rb', line 87

def add(array_element)
  case @type
  when :parsing then parsing_add(array_element)
  when :generation then generation_add(array_element)
  end
end

#merge(hash) ⇒ Object



80
81
82
83
84
85
# File 'lib/dsl/template.rb', line 80

def merge(hash)
  case @type
  when :parsing then parsing_merge(hash)
  when :generation then generation_merge(hash)
  end
end

#req(key) ⇒ Object



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

def req(key)
  case @type
  when :generation then generation_req(key)
  else fail(Error,"Method 'req' undefined for type '#{@type}'")
  end
end

#set(constant, val) ⇒ Object



55
56
57
58
59
60
# File 'lib/dsl/template.rb', line 55

def set(constant, val)
  case @type
  when :parsing then parsing_set(constant, val)
  when :generation then generation_set(constant, val)
  end 
end

#set?(constant, val) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/dsl/template.rb', line 76

def set?(constant, val)
  set(constant, val) unless val.nil?
end

#val(key) ⇒ Object



69
70
71
72
73
74
# File 'lib/dsl/template.rb', line 69

def val(key)
  case @type
  when :generation then generation_val(key)
  else fail(Error,"Method 'val' undefined for type '#{@type}'")
  end
end