class Retrospec::Puppet::Generators::ProviderGenerator

Attributes

context[R]
provider_type[RW]
template_dir[R]

Public Class Methods

new(module_path, spec_object = {}) click to toggle source

retrospec will initaialize this class so its up to you to set any additional variables you need in the context in feed the templates.

Calls superclass method
# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 11
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(:provider_name => spec_object[:name],
                            :type_name => spec_object[:type],
                            :properties => [])
  @provider_type = context.type_name
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/provider_generator.rb, line 40
    def self.run_cli(global_opts, args=ARGV)
      sub_command_opts = Optimist.options(args) do
        banner <<-EOS
Generates a new provider with the given name.

        EOS
        opt :name, 'The name of the provider you wish to create', :type => :string, :required => true, :short => '-n'
        opt :type, 'The type name of the provider', :type => :string, :required => true, :short => '-t'
      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/provider_generator.rb, line 89
def generate_provider_files
  safe_create_template_file(provider_name_path, File.join(template_dir, 'provider_template.rb.retrospec.erb'), context)
  provider_name_path
end
generate_provider_spec_files() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 94
def generate_provider_spec_files
  provider_files = Dir.glob(File.join(provider_dir, '**', '*.rb')).sort
  spec_files = []
  provider_files.each do |provider_file|
    t_name = File.basename(File.dirname(provider_file))
    provider_file_data = Retrospec::Puppet::Type.load_type(type_file(t_name), provider_file)
    provider_file_data.type_name = t_name # add the provider type
    # because many facts can be in a single file we want to create a unique file for each fact
    provider_spec_path = File.join(provider_spec_dir, t_name, "#{provider_file_data.name}_spec.rb")
    spec_files << provider_spec_path
    safe_create_template_file(provider_spec_path, File.join(template_dir, 'provider_spec.rb.retrospec.erb'), provider_file_data)
  end
  spec_files
end
provider_dir() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 57
def provider_dir
  File.join(module_path, 'lib', 'puppet', 'provider')
end
provider_name() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 85
def provider_name
  context.provider_name
end
provider_name_path() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 81
def provider_name_path
  File.join(provider_dir, provider_type, "#{provider_name}.rb")
end
provider_spec_dir() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 77
def provider_spec_dir
  File.join(module_path, 'spec', 'unit', 'puppet', 'provider')
end
type_dir() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 61
def type_dir
  File.join(module_path, 'lib', 'puppet', 'type')
end
type_file(p_type = provider_type) click to toggle source

returns the type file that the provider uses if the type file does not exist it assumes a core puppet type because we could potentially dealing with multiple

# File lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb, line 68
def type_file(p_type = provider_type)
  if TypeGenerator::CORE_TYPES.include?(p_type)
    type_file = "puppet/type/#{p_type}.rb"
  else
    type_file = File.join(type_dir, "#{p_type}.rb")
  end
  type_file
end