module SimplerCommand

Provides a simple structure for Commands (Services).

Prepend SimplerCommand to your Command (Service) objects and implemente a call methods.

In the advent of a failure, Log any errors to an errors object.

Constants

VERSION

Public Class Methods

prepended(base) click to toggle source
# File lib/simpler_command.rb, line 32
def self.prepended(base)
  base.extend ClassMethods
end

Public Instance Methods

call() { |result| ... } click to toggle source
Calls superclass method
# File lib/simpler_command.rb, line 36
def call(&block)
  raise NotImplementedError unless defined?(super)

  unless called?
    @called = true
    @result = super
  end

  yield result if block_given?

  self
end
errors() click to toggle source
Calls superclass method
# File lib/simpler_command.rb, line 64
def errors
  return super if defined?(super)

  @errors ||= Errors.new
end
failure?() click to toggle source
# File lib/simpler_command.rb, line 60
def failure?
  called? && errors.any?
end
result() click to toggle source
# File lib/simpler_command.rb, line 54
def result
  raise Failure, StringUtils.to_sentence(errors.full_messages) if failure?

  @result
end
success?() click to toggle source
# File lib/simpler_command.rb, line 49
def success?
  called? && !failure?
end
Also aliased as: successful?
successful?()
Alias for: success?

Private Instance Methods

called?() click to toggle source
# File lib/simpler_command.rb, line 72
def called?
  @called ||= false
end