Class: Retrospec::Puppet::Generators::SchemaGenerator
- Inherits:
-
Retrospec::Plugins::V1::Plugin
- Object
- Retrospec::Plugins::V1::Plugin
- Retrospec::Puppet::Generators::SchemaGenerator
- Defined in:
- lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#template_dir ⇒ Object
readonly
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.
Class Method Summary collapse
-
.run_cli(global_opts, args = ARGV) ⇒ Object
used to display subcommand options to the cli the global options are passed in for your usage optimist.rubyforge.org all options here are available in the config passed into config object returns the parameters.
Instance Method Summary collapse
-
#add_mapping(map_value) ⇒ Object
example “motd::motd_content” => { “type” => “str”, “required” => false },.
-
#create_map_content ⇒ Object
creates the schema in ruby object format.
-
#generate_schema_file ⇒ Object
generates the schema file, using a template.
-
#initialize(module_path, spec_object = {}) ⇒ SchemaGenerator
constructor
retrospec will initilalize this class so its up to you to set any additional variables you need to get the job done.
- #schema_name ⇒ Object
-
#schema_path ⇒ Object
absolute path of schema file.
- #types ⇒ Object
Constructor Details
#initialize(module_path, spec_object = {}) ⇒ SchemaGenerator
retrospec will initilalize this class so its up to you to set any additional variables you need to get the job done.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 12 def initialize(module_path, spec_object = {}) super # below is the Spec Object which serves as a context for template rendering # you will need to initialize this object, so the erb templates can get the binding # the SpecObject can be customized to your liking as its different for every plugin gem. @context = OpenStruct.new(:puppet_context => spec_object[:puppet_context], :map_content => '', :raw_maps => '',:parameter_count => '',:schema_path => '', :schema_name => '') @schema = base_schema @parameter_count = 0 end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
9 10 11 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 9 def context @context end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
8 9 10 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 8 def schema @schema end |
#template_dir ⇒ Object (readonly)
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.
27 28 29 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 27 def template_dir @template_dir end |
Class Method Details
.run_cli(global_opts, args = ARGV) ⇒ Object
used to display subcommand options to the cli the global options are passed in for your usage optimist.rubyforge.org all options here are available in the config passed into config object returns the parameters
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 41 def self.run_cli(global_opts, args=ARGV) sub_command_opts = Optimist.(args) do <<-EOS Generates a kwalify schema based off class parameters. EOS end plugin_data = global_opts.merge(sub_command_opts) plugin_data end |
Instance Method Details
#add_mapping(map_value) ⇒ Object
example “motd::motd_content” =>
"type" => "str",
"required" => false
,
87 88 89 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 87 def add_mapping(map_value) schema['mapping'].merge!(map_value) end |
#create_map_content ⇒ Object
creates the schema in ruby object format
53 54 55 56 57 58 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 53 def create_map_content all_hiera_data.each do |name, opts| add_mapping(name => opts) end schema end |
#generate_schema_file ⇒ Object
generates the schema file, using a template
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 70 def generate_schema_file map_content = create_map_content context.map_content = map_content.to_yaml context.raw_maps = map_content context.parameter_count = @parameter_count context.schema_path = schema_path context.schema_name = schema_name template_file = File.join(template_dir, 'schema_file.yaml.retrospec.erb') safe_create_template_file(schema_path, template_file, context) schema_path end |
#schema_name ⇒ Object
60 61 62 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 60 def schema_name puppet_context.module_name || File.basename(module_path) end |
#schema_path ⇒ Object
absolute path of schema file
65 66 67 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 65 def schema_path File.join(module_path, "#{schema_name}_schema.yaml") end |
#types ⇒ Object
91 92 93 |
# File 'lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb', line 91 def types context.puppet_context.types end |