module AyeCommander::Resultable::ClassMethods
Most of the functionality is at class level since it receives several class instance variables.
Public Instance Methods
new_result(values)
click to toggle source
Creates a new instance of a Command::Result with the received values and returns it.
# File lib/aye_commander/resultable.rb, line 27 def new_result(values) result_class.new(values) end
result(command, skip_cleanup = false)
click to toggle source
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.
# 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_class()
click to toggle source
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
# File lib/aye_commander/resultable.rb, line 36 def result_class const_defined?('Result') ? const_get('Result') : define_result_class end
Private Instance Methods
define_result_class()
click to toggle source
Defines the result class with the necessary modules so it can behave like a result
# File lib/aye_commander/resultable.rb, line 44 def define_result_class readers = self.readers command_class = self result = Class.new do @command_class = command_class include Result extend Result::ClassMethods attr_reader(*readers) end const_set 'Result', result end