Class: Retrospec::Puppet::Generators::ReportGenerator

Inherits:
BaseGenerator
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/generators/report_generator.rb

Instance Attribute Summary

Attributes inherited from BaseGenerator

#context, #generator_template_dir_name, #plural_name, #singular_name, #template_dir

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseGenerator

#generate_file_name, #generate_path, #get_binding, #item_name, #item_path, #item_spec_path, #lib_path, #logger, #spec_path

Constructor Details

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

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
# File 'lib/retrospec/plugins/v1/plugin/generators/report_generator.rb', line 9

def initialize(module_path, spec_object = {})
  super
  @plural_name = 'reports'
  @singular_name = 'report'
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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/retrospec/plugins/v1/plugin/generators/report_generator.rb', line 39

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

Instance Method Details

#generate_lib_filesObject



22
23
24
25
26
# File 'lib/retrospec/plugins/v1/plugin/generators/report_generator.rb', line 22

def generate_lib_files
  template_file = File.join(template_dir, 'report.rb.retrospec.erb')
  safe_create_template_file(item_path, template_file, context)
  item_path
end

#generate_spec_filesObject



28
29
30
31
32
# File 'lib/retrospec/plugins/v1/plugin/generators/report_generator.rb', line 28

def generate_spec_files
  template_file = File.join(template_dir, 'report_spec.rb.retrospec.erb')
  safe_create_template_file(item_spec_path, template_file, context)
  item_spec_path
end

#runObject



15
16
17
18
19
20
# File 'lib/retrospec/plugins/v1/plugin/generators/report_generator.rb', line 15

def run
  files = []
  files << generate_lib_files
  files << generate_spec_files
  files
end