Class: PuppetGenerator::Models::Template
- Inherits:
-
FeduxOrg::Stdlib::Models::BaseModel
- Object
- FeduxOrg::Stdlib::Models::BaseModel
- PuppetGenerator::Models::Template
- Includes:
- FeduxOrg::Stdlib::Models::FilesystemBasedModel
- Defined in:
- lib/puppet_generator/models/template.rb
Instance Method Summary collapse
-
#initialize(name, template_path, suitable_outputs = [], tags = []) ⇒ Template
constructor
create new instance of template model.
-
#is_suitable_for?(output) ⇒ Boolean
check if a template is suitable for a given output.
-
#is_tagged_with?(asked_tags) ⇒ Boolean
check if a template is tagged.
-
#path ⇒ Object
output path to template.
-
#render(items) ⇒ Object
render the template based on files.
Constructor Details
#initialize(name, template_path, suitable_outputs = [], tags = []) ⇒ Template
create new instance of template model
8 9 10 11 12 13 14 |
# File 'lib/puppet_generator/models/template.rb', line 8 def initialize( name , template_path, suitable_outputs=[], =[] ) super(name) @template_path = template_path @suitable_outputs = suitable_outputs @tags = end |
Instance Method Details
#is_suitable_for?(output) ⇒ Boolean
check if a template is suitable for a given output
23 24 25 |
# File 'lib/puppet_generator/models/template.rb', line 23 def is_suitable_for?(output) @suitable_outputs.include? output end |
#is_tagged_with?(asked_tags) ⇒ Boolean
check if a template is tagged
28 29 30 31 32 33 34 |
# File 'lib/puppet_generator/models/template.rb', line 28 def is_tagged_with?() if return .all? { |t| @tags.include? t } else return true end end |
#path ⇒ Object
output path to template
17 18 19 |
# File 'lib/puppet_generator/models/template.rb', line 17 def path @template_path end |
#render(items) ⇒ Object
render the template based on files
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/puppet_generator/models/template.rb', line 37 def render(items) if @tags.include? :many_per_file return [ Definition.new( nil , template.evaluate( items: items ) ) ] elsif @tags.include? :one_per_file return items.collect { |item| Definition.new( item.suggested_file_name, template.evaluate( item: item ) ) } else raise end rescue Exception => e raise Exceptions::InvalidTemplate, "An invalid template \"#{@template_path}\" was used. Please check and correct the syntax and try again. The original error message was: #{e.}." end |