Class | MCollective::Generators::AgentGenerator |
In: |
lib/mcollective/generators/agent_generator.rb
|
Parent: | Base |
content | [RW] | |
ddl | [RW] |
# File lib/mcollective/generators/agent_generator.rb, line 7 7: def initialize(plugin_name, actions = [], 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: @plugin_name = plugin_name 12: @actions = actions || [] 13: @ddl = create_ddl 14: @mod_name = "Agent" 15: @pclass = "RPC::Agent" 16: @content = create_plugin_content 17: @plugin = create_plugin_string 18: write_plugins 19: end
# File lib/mcollective/generators/agent_generator.rb, line 50 50: def action_help 51: action_snippet = File.read(File.join(File.dirname(__FILE__), "templates", "action_snippet.erb")) 52: ERB.new(action_snippet).result 53: end
# File lib/mcollective/generators/agent_generator.rb, line 21 21: def create_ddl 22: action_text = "" 23: @actions.each_with_index do |action, i| 24: action_text += "action \"#{action}\", :description => \"%ACTIONDESCRIPTION%\" do\n" 25: action_text += action_help if i == 0 26: action_text += "end\n" 27: action_text += "\n" unless @actions.size == (i + 1) 28: end 29: # Use inherited method to create metadata part of the ddl 30: create_metadata_string + action_text 31: end
# File lib/mcollective/generators/agent_generator.rb, line 33 33: def create_plugin_content 34: content_text = "" 35: 36: # Add metadata to agent file 37: create_metadata_string.each_line do |line| 38: content_text += "%6s%s" % [" ", line ] 39: end 40: 41: # Add actions to agent file 42: @actions.each_with_index do |action, i| 43: content_text += "%6s%s" % [" ", "action \"#{action}\" do\n"] 44: content_text += "%6s%s" % [" ", "end\n"] 45: content_text += "\n" unless @actions.size == (i + 1) 46: end 47: content_text 48: end