Class: Servizio::Service
- Inherits:
-
Object
show all
- Extended by:
- MethodDecorators
- Includes:
- ActiveModel::Model, ActiveModel::Validations
- Defined in:
- lib/servizio/service.rb
Defined Under Namespace
Modules: DefineColumnType, MethodDecorators
Constant Summary
collapse
- OperationFailedError =
Class.new(StandardError)
- OperationInvalidError =
Class.new(StandardError)
- OperationNotCalledError =
Class.new(StandardError)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
inherited
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
9
10
11
|
# File 'lib/servizio/service.rb', line 9
def result
@result
end
|
Class Method Details
.call(*args) ⇒ Object
shortcut to call operations, which returns the result or nik
21
22
23
24
25
26
27
|
# 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) ⇒ Object
shortcut to call operations, which returns the result and/or throws errors
.name ⇒ Object
16
17
18
|
# File 'lib/servizio/service.rb', line 16
def self.name
super ? super : "__anonymous_servizio_service_class__"
end
|
Instance Method Details
#called? ⇒ Boolean
48
49
50
|
# File 'lib/servizio/service.rb', line 48
def called?
@called == true
end
|
#failed!(error = :failed) ⇒ Object
52
53
54
55
|
# File 'lib/servizio/service.rb', line 52
def failed!(error = :failed)
errors[:call] = error
self end
|
#failed? ⇒ Boolean
57
58
59
|
# File 'lib/servizio/service.rb', line 57
def failed?
errors.present?
end
|
#succeeded? ⇒ Boolean
61
62
63
|
# File 'lib/servizio/service.rb', line 61
def succeeded?
called? && errors.blank?
end
|