Module: SimpleRubyService::ServiceObject

Extended by:
ActiveSupport::Concern
Includes:
Service
Defined in:
lib/simple_ruby_service/service_object.rb

Instance Method Summary collapse

Methods included from Service

#attributes, #failure?, #read_attribute_for_validation, #reset!, #success?, #valid?

Instance Method Details

#call(&callback) ⇒ Object

Returns self (for chainability). Memoizes to ‘value` the result of the blk provided. Evaluates validity prior to executing the block provided.



29
30
31
32
33
# File 'lib/simple_ruby_service/service_object.rb', line 29

def call(&callback)
  self.value = perform(&callback) if valid?

  self
end

#call!(&callback) ⇒ Object

Returns #value (i.e. the result of block provided). Raises Invalid if validation reports any errors. Raises Failure if the blk provided reports any errors.



38
39
40
41
42
43
44
# File 'lib/simple_ruby_service/service_object.rb', line 38

def call!(&callback)
  call(&callback)
  raise Invalid.new self, errors.full_messages unless valid?
  raise Failure.new self, errors.full_messages unless success?

  value
end