Class: Retrospec::Puppet::Generators::DataTypeGenerator
- Inherits:
-
ResourceBaseGenerator
- Object
- Retrospec::Plugins::V1::Plugin
- BaseGenerator
- ResourceBaseGenerator
- Retrospec::Puppet::Generators::DataTypeGenerator
- Defined in:
- lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb
Instance Attribute Summary
Attributes inherited from BaseGenerator
#context, #generator_template_dir_name, #plural_name, #singular_name
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(module_path, spec_object = {}) ⇒ DataTypeGenerator
constructor
A new instance of DataTypeGenerator.
- #load_context_data ⇒ Object
- #spec_template_file ⇒ Object
-
#template_dir ⇒ Object
returns the path to the templates first looks inside the external templates directory for specific file then looks inside the gem path templates directory, which is really only useful when developing new templates.
Methods inherited from ResourceBaseGenerator
#ast, #dumper, #find_all_resources, #generate_content, #generate_spec_file, #item_path, #item_spec_path, #lib_path, #manifest_body, #manifest_file, #parameters, #plural_name, #resource_type, #resource_type_name, #resources, #run, run_cli, #singular_name, #spec_path, #type_name
Methods inherited from BaseGenerator
#generate_file_name, #generate_lib_files, #generate_path, #generate_spec_files, #get_binding, #item_name, #item_path, #item_spec_path, #lib_path, #logger, #run, run_cli, #spec_path
Constructor Details
#initialize(module_path, spec_object = {}) ⇒ DataTypeGenerator
Returns a new instance of DataTypeGenerator.
10 11 12 13 14 |
# File 'lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb', line 10 def initialize(module_path, spec_object = {}) super @singular_name = 'type_alias' @plural_name = 'type_aliases' end |
Class Method Details
.generate_spec_files(module_path, config_data) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb', line 33 def self.generate_spec_files(module_path, config_data) manifest_files(module_path).map do |file| datatype = new(module_path, config_data.merge({:manifest_file => file})) next unless datatype.resource_type == ::Puppet::Pops::Model::TypeAlias datatype.generate_spec_file end.flatten end |
.manifest_files(module_path) ⇒ Object
16 17 18 |
# File 'lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb', line 16 def self.manifest_files(module_path) Dir.glob(File.join(module_path, 'types', '**', '*.pp')) end |
Instance Method Details
#load_context_data ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb', line 24 def load_context_data context.content = generate_content context.parameters = parameters context.type_name = type_name context.resource_type = resource_type context.resource_type_name = resource_type_name context end |
#spec_template_file ⇒ Object
20 21 22 |
# File 'lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb', line 20 def spec_template_file 'datatype_spec.rb.retrospec.erb' end |
#template_dir ⇒ Object
returns the path to the templates first looks inside the external templates directory for specific file then looks inside the gem path templates directory, which is really only useful when developing new templates.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/retrospec/plugins/v1/plugin/generators/data_type_generator.rb', line 45 def template_dir if config_data[:template_dir] external_templates = Dir.glob(File.(File.join(config_data[:template_dir], 'type_aliases', '*.erb'))) end if external_templates and external_templates.count > 0 File.join(config_data[:template_dir], 'type_aliases') else File.(File.join(File.dirname(File.dirname(__FILE__)), 'templates', 'type_aliases')) end end |