module MiniTools::Command

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) ->(message) { puts 'Successful'; puts message }
response.on(:failure) ->(message) { puts 'Unsuccessful'; puts message }
response.else ->(message) { puts 'Unknown response type'; puts message }

end

Public Instance Methods

handled=(result) click to toggle source
# File lib/mini_tools/command.rb, line 33
def handled= result
  @handled = result
end
handled?() click to toggle source
# File lib/mini_tools/command.rb, line 29
def handled?
  @handled
end
response(result, *args) click to toggle source
# File lib/mini_tools/command.rb, line 25
def response result, *args
  Response.new(self, result, *args)
end