class Light::Services::Base

Attributes

args[R]

Getters

errors[R]

Getters

warnings[R]

Getters

Public Class Methods

call(args = {}) click to toggle source
# File lib/light/services/base.rb, line 37
def call(args = {})
  new(args).tap(&:call)
end
Also aliased as: run
new(args = {}) click to toggle source
# File lib/light/services/base.rb, line 14
def initialize(args = {})
  @args = args

  initialize_params
  initialize_outputs

  @errors   = Light::Services::Messages.new
  @warnings = Light::Services::Messages.new
end
run(args = {})
Alias for: call

Public Instance Methods

any_warnings?() click to toggle source
# File lib/light/services/base.rb, line 32
def any_warnings?
  warnings.any?
end
call() click to toggle source
# File lib/light/services/base.rb, line 24
def call
  within_transaction { run_service }
end
success?() click to toggle source
# File lib/light/services/base.rb, line 28
def success?
  errors.blank?
end

Private Instance Methods

run_service() click to toggle source
# File lib/light/services/base.rb, line 49
def run_service
  run_callbacks(:before)
  run if success?
  run_callbacks(:after) if success?
  run_callbacks(:finally, force_run: true)
  success?
end
within_transaction() { || ... } click to toggle source
# File lib/light/services/base.rb, line 57
def within_transaction
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.transaction do
      yield
    end
  else
    yield
  end
end