Class: MCollective::Generators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/generators/base.rb

Direct Known Subclasses

AgentGenerator, DataGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

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, author, license, version, url, timeout)
  @meta = {:name => name,
           :description => description,
           :author => author,
           :license => license,
           :version => version,
           :url => url,
           :timeout => timeout}
end

Instance Attribute Details

#metaObject

Returns the value of attribute meta.



4
5
6
# File 'lib/mcollective/generators/base.rb', line 4

def meta
  @meta
end

#mod_nameObject

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_nameObject

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_stringObject



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_stringObject



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_pluginsObject



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