class MCollective::Generators::Base - mcollective version 2.12.5

# class MCollective::Generators::Base

### Attributes

meta[RW]
mod_name[RW]
plugin_name[RW]

### Public Class Methods

new(name, description, author, license, version, url, timeout) click to toggle source

       # File lib/mcollective/generators/base.rb
     5 def initialize(name, description, author, license, version, url, timeout)
     6   @meta = {:name => name,
     7            :description => description,
     8            :author => author,
     9            :license => license,
    10            :version => version,
    11            :url => url,
    12            :timeout => timeout}
    13 end

### Public Instance Methods

create_metadata_string() click to toggle source

       # File lib/mcollective/generators/base.rb
    15 def create_metadata_string
    16   ddl_template = File.read(File.join(File.dirname(__FILE__), "templates", "ddl.erb"))
    17   ERB.new(ddl_template, nil, "-").result(binding)
    18 end

create_plugin_string() click to toggle source

       # File lib/mcollective/generators/base.rb
    20 def create_plugin_string
    21   plugin_template = File.read(File.join(File.dirname(__FILE__), "templates", "plugin.erb"))
    22   ERB.new(plugin_template, nil, "-").result(binding)
    23 end

write_plugins() click to toggle source

       # File lib/mcollective/generators/base.rb
    25 def write_plugins
    26   begin
    27     Dir.mkdir @plugin_name
    28     dirname = File.join(@plugin_name, @mod_name.downcase)
    29     Dir.mkdir dirname
    30     puts "Created plugin directory : #{@plugin_name}"
    31
    32     File.open(File.join(dirname, "#{@plugin_name}.ddl"), "w"){|f| f.puts @ddl}
    33     puts "Created DDL file : #{File.join(dirname, "#{@plugin_name}.ddl")}"
    34
    35     File.open(File.join(dirname, "#{@plugin_name}.rb"), "w"){|f| f.puts @plugin}
    36     puts "Created #{@mod_name} file : #{File.join(dirname, "#{@plugin_name}.rb")}"
    37   rescue Errno::EEXIST
    38     raise "cannot generate '#{@plugin_name}' : plugin directory already exists."
    39   rescue Exception => e
    40     FileUtils.rm_rf(@plugin_name) if File.directory?(@plugin_name)
    41     raise "cannot generate plugin - #{e}"
    42   end
    43 end