Module: MiniTools::Command
- Defined in:
- lib/mini_tools/command.rb
Overview
Creates a very simple command object using the MiniTools::Response class
“‘ class SimpleCommand
include MiniTools::Command
def call value
yield response :success, 'It worked' if value == true
yield response :failure, 'It failed' if value == false
end
end “‘
Then use with
SimpleCommand.new.call some_value do |response|
response.on(:success) ->() { puts 'Successful'; puts }
response.on(:failure) ->() { puts 'Unsuccessful'; puts }
response.else ->() { puts 'Unknown response type'; puts }
end
Instance Method Summary collapse
Instance Method Details
#handled=(result) ⇒ Object
33 34 35 |
# File 'lib/mini_tools/command.rb', line 33 def handled= result @handled = result end |
#handled? ⇒ Boolean
29 30 31 |
# File 'lib/mini_tools/command.rb', line 29 def handled? @handled end |
#response(result, *args) ⇒ Object
25 26 27 |
# File 'lib/mini_tools/command.rb', line 25 def response result, *args Response.new(self, result, *args) end |