Class: MCollective::Generators::DataGenerator

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

Instance Attribute Summary collapse

Attributes inherited from Base

#meta, #mod_name, #plugin_name

Instance Method Summary collapse

Methods inherited from Base

#create_metadata_string, #create_plugin_string, #write_plugins

Constructor Details

#initialize(plugin_name, outputs = [], name = nil, description = nil, author = nil, license = nil, version = nil, url = nil, timeout = nil) ⇒ DataGenerator

Returns a new instance of DataGenerator.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mcollective/generators/data_generator.rb', line 7

def initialize(plugin_name, outputs = [],  name = nil, description = nil, author = nil ,
               license = nil, version = nil, url = nil, timeout = nil)

  super(name, description, author, license, version, url, timeout)
  @mod_name = "Data"
  @pclass = "Base"
  @plugin_name = plugin_name
  @outputs = outputs
  @ddl = create_ddl
  @content = create_plugin_content
  @plugin = create_plugin_string
  write_plugins
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/mcollective/generators/data_generator.rb', line 5

def content
  @content
end

#ddlObject

Returns the value of attribute ddl.



5
6
7
# File 'lib/mcollective/generators/data_generator.rb', line 5

def ddl
  @ddl
end

Instance Method Details

#create_ddlObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mcollective/generators/data_generator.rb', line 21

def create_ddl
  query_text = "dataquery :description => \"Query information\" do\n"
  query_text += ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "data_input_snippet.erb"))).result

  @outputs.each_with_index do |output,i|
    query_text += "%2s%s" % [" ", "output :#{output},\n"]
    query_text += "%9s%s" % [" ", ":description => \"%DESCRIPTION%\",\n"]
    query_text += "%9s%s" % [" ", ":display_as => \"%DESCRIPTION%\"\n"]
    query_text += "\n" unless @outputs.size == (i + 1)
  end

  query_text += "end"

  # Use inherited method to create metadata part of the ddl
   + query_text
end

#create_plugin_contentObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mcollective/generators/data_generator.rb', line 38

def create_plugin_content
  content_text = "%6s%s" % [" ", "query do |what|\n"]

  @outputs.each do |output|
     content_text += "%8s%s" % [" ", "result[:#{output}] = nil\n"]
  end
  content_text += "%6s%s" % [" ", "end\n"]

  # Add actions to agent file
  content_text
end