class Retrospec::Puppet::Generators::TypeGenerator
Constants
- CORE_TYPES
this is the list of core puppet types that cannot be recreated
Attributes
context[R]
template_dir[R]
Public Class Methods
new(module_path, spec_object = {})
click to toggle source
retrospec will initilalize this class so its up to you to set any additional variables you need to get the job done.
Calls superclass method
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 24 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. if CORE_TYPES.include?(spec_object[:name]) raise Retrospec::Puppet::Generators::CoreTypeException end @context = OpenStruct.new(:type_name => spec_object[:name], name: spec_object[:name], :parameters => spec_object[:parameters], :properties => spec_object[:properties], :providers => spec_object[:providers]) end
run_cli(global_opts, args=ARGV)
click to toggle source
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
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 49 def self.run_cli(global_opts, args=ARGV) sub_command_opts = Optimist.options(args) do banner <<-EOS Generates a new type with the given name, parameters, and properties. EOS opt :name, 'The name of the type you wish to create', :type => :string, :required => true, :short => '-n' opt :parameters, 'A list of parameters to initialize your type with', :type => :strings, :required => false, :short => '-p', :default => ['name'] opt :properties, 'A list of properties to initialize your type with', :type => :strings, :required => false, :short => '-a', :default => [] opt :providers, 'A list of providers to create and associate with this type', :type => :strings, :default => ['default'], :required => false end unless sub_command_opts[:name] Optimist.educate exit 1 end plugin_data = global_opts.merge(sub_command_opts) plugin_data end
Public Instance Methods
generate_provider_files()
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 87 def generate_provider_files providers = context.providers providers.each do |provider| plugin_data = { :name => provider, :type => type_name, :template_dir => config_data[:template_dir] } p = Retrospec::Puppet::Generators::ProviderGenerator.new(module_path, plugin_data) p.generate_provider_files end end
generate_type_files()
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 96 def generate_type_files safe_create_template_file(type_name_path, File.join(template_dir, 'type_template.rb.retrospec.erb'), context) generate_provider_files type_name_path end
generate_type_spec_files()
click to toggle source
this will look through all
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 103 def generate_type_spec_files type_files = Dir.glob(File.join(type_dir, '**', '*.rb')).sort spec_files = [] type_files.each do |type_file| type_file_data = Retrospec::Puppet::Type.load_type(type_file) # because many facts can be in a single file we want to create a unique file for each fact type_spec_path = File.join(type_spec_dir, "#{type_file_data.name}_spec.rb") spec_files << type_spec_path safe_create_template_file(type_spec_path, File.join(template_dir, 'type_spec.rb.retrospec.erb'), type_file_data) end spec_files end
type_dir()
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 71 def type_dir @type_dir ||= File.join(module_path, 'lib', 'puppet', 'type') end
type_name()
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 83 def type_name context.type_name end
type_name_path()
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 79 def type_name_path File.join(type_dir, "#{type_name}.rb") end
type_spec_dir()
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/type_generator.rb, line 75 def type_spec_dir @type_spec_dir ||= File.join(module_path, 'spec', 'unit', 'puppet', 'type') end