Class: CommandEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_type/command_entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, arguments, options = {}) ⇒ CommandEntry

rubocop:enable ClassVars



18
19
20
21
22
# File 'lib/easy_type/command_entry.rb', line 18

def initialize(command, arguments, options = {})
  @command    = command
  @arguments  = arguments.is_a?(Array) ? arguments : [arguments]
  @options    = options
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



10
11
12
# File 'lib/easy_type/command_entry.rb', line 10

def arguments
  @arguments
end

#commandObject (readonly)

Returns the value of attribute command.



10
11
12
# File 'lib/easy_type/command_entry.rb', line 10

def command
  @command
end

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/easy_type/command_entry.rb', line 10

def context
  @context
end

Class Method Details

.set_binding(the_binding) ⇒ Object

rubocop:disable ClassVars



13
14
15
# File 'lib/easy_type/command_entry.rb', line 13

def self.set_binding(the_binding)
  @@binding = the_binding
end

Instance Method Details

#executeObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/easy_type/command_entry.rb', line 24

def execute
  normalized_command = ''
  normalized_command = command.to_sym
  if @@binding.methods.include?(normalized_command)
    @@binding.send(normalized_command, normalized_arguments, @options)
  else
    full_command = arguments.dup.unshift(command).join(' ')
    Puppet::Util::Execution.execute(full_command, :failonfail => true)
  end
end