class Servizio::Service
Constants
- OperationFailedError
- OperationInvalidError
- OperationNotCalledError
Attributes
result[RW]
Public Class Methods
call(*args)
click to toggle source
shortcut to call operations, which returns the result or nik
# File lib/servizio/service.rb, line 21 def self.call(*args) operation = self.new(*args) if operation.valid? && operation.call!.succeeded? operation.result end end
call!(*args)
click to toggle source
shortcut to call operations, which returns the result and/or throws errors
# File lib/servizio/service.rb, line 30 def self.call!(*args) operation = self.new(*args) if operation.valid? if operation.call!.succeeded? operation.result else raise Servizio::Service::OperationFailedError end else raise Servizio::Service::OperationInvalidError end end
name()
click to toggle source
stackoverflow.com/questions/14431723/activemodelvalidations-on-anonymous-class
Calls superclass method
# File lib/servizio/service.rb, line 16 def self.name super ? super : "__anonymous_servizio_service_class__" end
Public Instance Methods
called?()
click to toggle source
# File lib/servizio/service.rb, line 48 def called? @called == true end
failed!(error = :failed)
click to toggle source
# File lib/servizio/service.rb, line 52 def failed!(error = :failed) errors[:call] = error self # for chaining end
failed?()
click to toggle source
# File lib/servizio/service.rb, line 57 def failed? errors.present? end
succeeded?()
click to toggle source
# File lib/servizio/service.rb, line 61 def succeeded? called? && errors.blank? end