Module: MiniTools::Command

Defined in:
lib/mini_tools/command.rb

Overview

Creates a very simple command object using the MiniTools::Response class

“‘ class SimpleCommand

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 }

end

Instance Method Summary collapse

Instance Method Details

#response(result, *args) ⇒ Object



22
23
24
# File 'lib/mini_tools/command.rb', line 22

def response result, *args
  Response.new(result, *args)
end