Class: MCollective::Generators::Base
- Inherits:
-
Object
- Object
- MCollective::Generators::Base
- Defined in:
- lib/mcollective/generators/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#mod_name ⇒ Object
Returns the value of attribute mod_name.
-
#plugin_name ⇒ Object
Returns the value of attribute plugin_name.
Instance Method Summary collapse
- #create_metadata_string ⇒ Object
- #create_plugin_string ⇒ Object
-
#initialize(name, description, author, license, version, url, timeout) ⇒ Base
constructor
A new instance of Base.
- #write_plugins ⇒ Object
Constructor Details
#initialize(name, description, author, license, version, url, timeout) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 |
# File 'lib/mcollective/generators/base.rb', line 5 def initialize(name, description, , license, version, url, timeout) @meta = {:name => name, :description => description, :author => , :license => license, :version => version, :url => url, :timeout => timeout} end |
Instance Attribute Details
#meta ⇒ Object
Returns the value of attribute meta.
4 5 6 |
# File 'lib/mcollective/generators/base.rb', line 4 def @meta end |
#mod_name ⇒ Object
Returns the value of attribute mod_name.
4 5 6 |
# File 'lib/mcollective/generators/base.rb', line 4 def mod_name @mod_name end |
#plugin_name ⇒ Object
Returns the value of attribute plugin_name.
4 5 6 |
# File 'lib/mcollective/generators/base.rb', line 4 def plugin_name @plugin_name end |
Instance Method Details
#create_metadata_string ⇒ Object
15 16 17 18 |
# File 'lib/mcollective/generators/base.rb', line 15 def ddl_template = File.read(File.join(File.dirname(__FILE__), "templates", "ddl.erb")) ERB.new(ddl_template, nil, "-").result(binding) end |
#create_plugin_string ⇒ Object
20 21 22 23 |
# File 'lib/mcollective/generators/base.rb', line 20 def create_plugin_string plugin_template = File.read(File.join(File.dirname(__FILE__), "templates", "plugin.erb")) ERB.new(plugin_template, nil, "-").result(binding) end |
#write_plugins ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mcollective/generators/base.rb', line 25 def write_plugins begin Dir.mkdir @plugin_name dirname = File.join(@plugin_name, @mod_name.downcase) Dir.mkdir dirname puts "Created plugin directory : #{@plugin_name}" File.open(File.join(dirname, "#{@plugin_name}.ddl"), "w"){|f| f.puts @ddl} puts "Created DDL file : #{File.join(dirname, "#{@plugin_name}.ddl")}" File.open(File.join(dirname, "#{@plugin_name}.rb"), "w"){|f| f.puts @plugin} puts "Created #{@mod_name} file : #{File.join(dirname, "#{@plugin_name}.rb")}" rescue Errno::EEXIST raise "cannot generate '#{@plugin_name}' : plugin directory already exists." rescue Exception => e FileUtils.rm_rf(@plugin_name) if File.directory?(@plugin_name) raise "cannot generate plugin - #{e}" end end |