Class: Retrospec::Puppet::Generators::BaseGenerator
- Inherits:
-
Retrospec::Plugins::V1::Plugin
- Object
- Retrospec::Plugins::V1::Plugin
- Retrospec::Puppet::Generators::BaseGenerator
- Defined in:
- lib/retrospec/plugins/v1/plugin/generators/base_generator.rb
Direct Known Subclasses
ModuleDataGenerator, ReportGenerator, ResourceBaseGenerator, TaskGenerator
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#generator_template_dir_name ⇒ Object
readonly
Returns the value of attribute generator_template_dir_name.
-
#plural_name ⇒ Object
readonly
Returns the value of attribute plural_name.
-
#singular_name ⇒ Object
readonly
Returns the value of attribute singular_name.
-
#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 trollop.rubyforge.org all options here are available in the config passed into config object returns the parameters.
Instance Method Summary collapse
- #generate_lib_files ⇒ Object
- #generate_spec_files ⇒ Object
- #get_binding ⇒ Object
-
#initialize(module_path, spec_object = {}) ⇒ BaseGenerator
constructor
retrospec will initilalize this class so its up to you to set any additional variables you need to get the job done.
- #item_name ⇒ Object
- #item_path ⇒ Object
- #item_spec_path ⇒ Object
- #lib_path ⇒ Object
- #logger ⇒ Object
-
#run ⇒ Object
run is the main method that gets called automatically.
- #spec_path ⇒ Object
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
#context ⇒ Object
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_name ⇒ Object (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_name ⇒ Object (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_name ⇒ Object (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_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.
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.(args) do <<-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_files ⇒ Object
41 42 43 |
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 41 def generate_lib_files raise NotImplementedError end |
#generate_spec_files ⇒ Object
45 46 47 |
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 45 def generate_spec_files raise NotImplementedError end |
#get_binding ⇒ Object
89 90 91 |
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 89 def get_binding binding end |
#item_name ⇒ Object
54 55 56 |
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 54 def item_name context.name end |
#item_path ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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 |
#logger ⇒ Object
17 18 19 |
# File 'lib/retrospec/plugins/v1/plugin/generators/base_generator.rb', line 17 def logger Retrospec::Plugins::V1::Puppet.logger end |
#run ⇒ Object
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_path ⇒ Object
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 |