class MCollective::Generators::DataGenerator

Attributes

content[RW]
ddl[RW]

Public Class Methods

new(plugin_name, outputs = [], name = nil, description = nil, author = nil , license = nil, version = nil, url = nil, timeout = nil) click to toggle source
Calls superclass method MCollective::Generators::Base::new
   # File lib/mcollective/generators/data_generator.rb
 7 def initialize(plugin_name, outputs = [],  name = nil, description = nil, author = nil ,
 8                license = nil, version = nil, url = nil, timeout = nil)
 9 
10   super(name, description, author, license, version, url, timeout)
11   @mod_name = "Data"
12   @pclass = "Base"
13   @plugin_name = plugin_name
14   @outputs = outputs
15   @ddl = create_ddl
16   @content = create_plugin_content
17   @plugin = create_plugin_string
18   write_plugins
19 end

Public Instance Methods

create_ddl() click to toggle source
   # File lib/mcollective/generators/data_generator.rb
21 def create_ddl
22   query_text = "dataquery :description => \"Query information\" do\n"
23   query_text += ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "data_input_snippet.erb"))).result
24 
25   @outputs.each_with_index do |output,i|
26     query_text += "%2s%s" % [" ", "output :#{output},\n"]
27     query_text += "%9s%s" % [" ", ":description => \"%DESCRIPTION%\",\n"]
28     query_text += "%9s%s" % [" ", ":display_as => \"%DESCRIPTION%\"\n"]
29     query_text += "\n" unless @outputs.size == (i + 1)
30   end
31 
32   query_text += "end"
33 
34   # Use inherited method to create metadata part of the ddl
35   create_metadata_string + query_text
36 end
create_plugin_content() click to toggle source
   # File lib/mcollective/generators/data_generator.rb
38 def create_plugin_content
39   content_text = "%6s%s" % [" ", "query do |what|\n"]
40 
41   @outputs.each do |output|
42      content_text += "%8s%s" % [" ", "result[:#{output}] = nil\n"]
43   end
44   content_text += "%6s%s" % [" ", "end\n"]
45 
46   # Add actions to agent file
47   content_text
48 end