Class: Retrospec::Puppet::Generators::BaseGenerator

Inherits:
Retrospec::Plugins::V1::Plugin
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/generators/base_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_path, spec_object = {}) ⇒ BaseGenerator

retrospec will initilalize this class so its up to you to set any additional variables you need to get the job done.



9
10
11
12
13
14
15
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 9

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(spec_object)
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



6
7
8
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 6

def context
  @context
end

#generator_template_dir_nameObject (readonly)

Returns the value of attribute generator_template_dir_name.



5
6
7
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 5

def generator_template_dir_name
  @generator_template_dir_name
end

#plural_nameObject (readonly)

Returns the value of attribute plural_name.



5
6
7
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 5

def plural_name
  @plural_name
end

#singular_nameObject (readonly)

Returns the value of attribute singular_name.



5
6
7
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 5

def singular_name
  @singular_name
end

#template_dirObject (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.



78
79
80
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 78

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 trollop.rubyforge.org all options here are available in the config passed into config object returns the parameters



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 26

def self.run_cli(global_opts, args=ARGV)
  sub_command_opts = Trollop.options(args) do
    banner <<-EOS
    ""
    EOS
    opt :name, "The name of the item you wish to create", :type => :string, :required => true, :short => '-n'
  end
  unless sub_command_opts[:name]
    Trollop.educate
    exit 1
  end
  plugin_data = global_opts.merge(sub_command_opts)
  plugin_data
end

Instance Method Details

#generate_lib_filesObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 41

def generate_lib_files
  raise NotImplementedError
end

#generate_spec_filesObject

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 45

def generate_spec_files
  raise NotImplementedError
end

#get_bindingObject



89
90
91
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 89

def get_binding
  binding
end

#item_nameObject



54
55
56
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 54

def item_name
  context.name
end

#item_pathObject



58
59
60
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 58

def item_path
  File.join(lib_path, "#{item_name}.rb")
end

#item_spec_pathObject



62
63
64
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 62

def item_spec_path
  File.join(spec_path, "#{item_name}_spec.rb")
end

#lib_pathObject



70
71
72
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 70

def lib_path
  File.join(module_path, 'lib', 'puppet', plural_name)
end

#loggerObject



17
18
19
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 17

def logger
  Retrospec::Plugins::V1::Puppet.logger
end

#runObject

run is the main method that gets called automatically



50
51
52
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 50

def run
  generate_lib_files
end

#spec_pathObject



66
67
68
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 66

def spec_path
  File.join(module_path, 'spec', 'unit', 'puppet', plural_name)
end