Module: AyeCommander::Resultable::ClassMethods

Included in:
Command::ClassMethods
Defined in:
lib/aye_commander/resultable.rb

Overview

Most of the functionality is at class level since it receives several class instance variables.

Instance Method Summary collapse

Instance Method Details

#new_result(values) ⇒ Object

Creates a new instance of a Command::Result with the received values and returns it.



27
28
29
# File 'lib/aye_commander/resultable.rb', line 27

def new_result(values)
  result_class.new(values)
end

#result(command, skip_cleanup = false) ⇒ Object

Returns a result based on the skip_cleanup option skip_cleanup

false    (Default) Returns a result taking returns in account
true     Returns the result skipping the cleanup.
:command Using this option asks to get the command instance rather
         than a result. This of course means the command is not clean.


14
15
16
17
18
19
20
21
22
23
# File 'lib/aye_commander/resultable.rb', line 14

def result(command, skip_cleanup = false)
  case skip_cleanup
  when :command
    command
  when true
    new_result(command.to_hash)
  else
    new_result(command.to_result_hash)
  end
end

#result_classObject

Returns and/or defines the Result class to be returned by the current command. This class is created under the namespace of the command so the end result looks pretty damn cool in my opinion. Eg: Command::Result



36
37
38
# File 'lib/aye_commander/resultable.rb', line 36

def result_class
  const_defined?('Result') ? const_get('Result') : define_result_class
end