Class: GroupTemplateDefinition
- Inherits:
-
Object
- Object
- GroupTemplateDefinition
- Defined in:
- lib/ccios/group_template_definition.rb
Instance Method Summary collapse
- #generate(parser, project, context, template_definition, config) ⇒ Object
-
#initialize(group_template_definition_hash) ⇒ GroupTemplateDefinition
constructor
A new instance of GroupTemplateDefinition.
- #validate(parser, project, context, template_definition, config) ⇒ Object
Constructor Details
#initialize(group_template_definition_hash) ⇒ GroupTemplateDefinition
Returns a new instance of GroupTemplateDefinition.
6 7 8 9 10 11 |
# File 'lib/ccios/group_template_definition.rb', line 6 def initialize(group_template_definition_hash) @name = group_template_definition_hash["name"] @path = group_template_definition_hash["group"] @template = group_template_definition_hash["path"] @variables = group_template_definition_hash["variables"] || {} end |
Instance Method Details
#generate(parser, project, context, template_definition, config) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ccios/group_template_definition.rb', line 29 def generate(parser, project, context, template_definition, config) merged_variables = config.variables_for_template_element(template_definition, @name, @variables) base_path = merged_variables["base_path"] base_group = project[base_path] group_path = CodeTemplater.new.render_string(@path, context) group_path = group_path.split("/") group = base_group associate_path_to_group = !base_group.path.nil? group_path.each do |group_name| new_group_path = File.join(group.real_path, group_name) existing_group = group.groups.find { |g| g.display_name == group_name } group = existing_group || group.pf_new_group( associate_path_to_group: associate_path_to_group, name: group_name, path: new_group_path ) end file_creator = FileCreator.new file_creator.create_empty_directory(group) end |
#validate(parser, project, context, template_definition, config) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ccios/group_template_definition.rb', line 13 def validate(parser, project, context, template_definition, config) merged_variables = config.variables_for_template_element(template_definition, @name, @variables) code_templater = CodeTemplater.new pathTags = code_templater.get_unknown_context_keys_for_string(@path) pathTags.each do |tag| raise "Unknown parameter \"#{tag}\" in path \"#{@path}\"" if context[tag].nil? end base_path = merged_variables["base_path"] raise "Missing base_path variable" if base_path.nil? base_group = project[base_path] raise "Base path \"#{base_path}\" is missing" if base_group.nil? end |