Class: Hieracles::Commands
- Inherits:
-
Object
- Object
- Hieracles::Commands
- Defined in:
- lib/hieracles/commands.rb
Instance Attribute Summary collapse
-
#available ⇒ Object
readonly
Returns the value of attribute available.
Instance Method Summary collapse
- #call_node(command, fqdn, extra) ⇒ Object
- #farms(arg, extra) ⇒ Object
-
#initialize(config) ⇒ Commands
constructor
A new instance of Commands.
- #modules(arg, extra) ⇒ Object
- #run(command, arg, extra) ⇒ Object
Constructor Details
#initialize(config) ⇒ Commands
Returns a new instance of Commands.
7 8 9 10 11 |
# File 'lib/hieracles/commands.rb', line 7 def initialize(config) @config = config @formatter = Object.const_get("Hieracles::Formats::#{@config.format}") @available = %w(info files params paths modules allparams facts) end |
Instance Attribute Details
#available ⇒ Object (readonly)
Returns the value of attribute available.
5 6 7 |
# File 'lib/hieracles/commands.rb', line 5 def available @available end |
Instance Method Details
#call_node(command, fqdn, extra) ⇒ Object
52 53 54 55 56 |
# File 'lib/hieracles/commands.rb', line 52 def call_node(command, fqdn, extra) node = Hieracles::Node.new fqdn, @config formatter = @formatter.new node formatter.send command, extra end |
#farms(arg, extra) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hieracles/commands.rb', line 30 def farms(arg, extra) if arg arg = [arg] else arg = [] end formatter = @formatter.new nil farms = Hieracles::Registry.farms_nodes(@config, 'local', true) puts formatter.build_list(farms, nil, arg) end |
#modules(arg, extra) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hieracles/commands.rb', line 41 def modules(arg, extra) if arg arg = [arg] else arg = [] end formatter = @formatter.new nil modules = Hieracles::Registry.nodes_modules(@config, 'local', arg) puts formatter.build_list(modules, nil, arg) end |
#run(command, arg, extra) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hieracles/commands.rb', line 13 def run(command, arg, extra) if arg and arg[/\./] # poor way to detect if it is a fqdn if Hieracles::Registry.nodes(@config).include? arg puts call_node(command.to_sym, arg, extra) else puts "node '#{arg}' not found" end else if respond_to? command send command.to_sym, arg, extra else # not a node puts "'#{arg}' is not a FQDN." end end end |