Class: Retrospec::Plugins::V1::PluginGen

Inherits:
Plugin
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/plugin_gen.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(supplied_module_path = '.', config = {}) ⇒ PluginGen

Returns a new instance of PluginGen.



12
13
14
15
# File 'lib/retrospec/plugins/v1/plugin/plugin_gen.rb', line 12

def initialize(supplied_module_path='.',config={})
  super
  @context = ::PluginGen::SpecObject.new(module_path, config)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/retrospec/plugins/v1/plugin/plugin_gen.rb', line 10

def context
  @context
end

Class Method Details

.run_cli(global_opts, global_config, plugin_config, args = ARGV) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/retrospec/plugins/v1/plugin/plugin_gen.rb', line 23

def self.run_cli(global_opts, global_config, plugin_config, args=ARGV)
  # a list of subcommands for this plugin
  sub_commands  = []
  if sub_commands.count > 0
    sub_command_help = "Subcommands:\n#{sub_commands.join("\n")}\n"
  else
    sub_command_help = ""
  end
  plugin_opts = Trollop::options do
    version "#{Retrospec::PluginGen::VERSION} (c) Corey Osman"
    banner <<-EOS
A generator to create plugins for retrospec\n
#{sub_command_help}

    EOS
    opt :name, "The name of the new plugin", :require => false, :short => '-n', :type => :string, :default => File.basename(File.expand_path(global_opts[:module_path]))
    stop_on sub_commands
  end
  # the passed in options will always override the config file
  plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_config).merge(plugin_opts)
  # define the default action to use the plugin here, the default is run
  sub_command = (args.shift || :run).to_sym
  # create an instance of this plugin
  plugin = self.new(plugin_data[:module_path],plugin_data)
  # check if the plugin supports the sub command
  if plugin.respond_to?(sub_command)
    plugin.send(sub_command)
  else
    puts "The subcommand #{sub_command} is not supported or valid"
    exit 1
  end
end

Instance Method Details

#runObject



17
18
19
20
21
# File 'lib/retrospec/plugins/v1/plugin/plugin_gen.rb', line 17

def run
  safe_create_module_files(template_dir, module_path, context)
  create_main_file
  create_plugin_file
end