Class: Basic::Service
- Inherits:
-
Object
- Object
- Basic::Service
- Defined in:
- lib/basic_service.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
method error if call not defined.
- #error(str = '') ⇒ Object
-
#initialize(*args) ⇒ Service
constructor
A new instance of Service.
- #success(str = '') ⇒ Object
-
#success? ⇒ Boolean
Defaults to the boolean’ed result of “call”.
Constructor Details
#initialize(*args) ⇒ Service
Returns a new instance of Service.
25 26 27 28 29 30 |
# File 'lib/basic_service.rb', line 25 def initialize(*args) @args = args @success = false @error = false @pristine = false end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
33 34 35 |
# File 'lib/basic_service.rb', line 33 def end |
#result ⇒ Object
Returns the value of attribute result.
32 33 34 |
# File 'lib/basic_service.rb', line 32 def result @result end |
Class Method Details
.call(args) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/basic_service.rb', line 5 def self.call(args) new(args).tap do |basic_service| basic_service.instance_eval do self.result = call end end end |
Instance Method Details
#call ⇒ Object
method error if call not defined
44 45 46 |
# File 'lib/basic_service.rb', line 44 def call raise NoMethodError, "Called undefined #call. You need to implement the method in the class: #{self.class.name}" end |
#error(str = '') ⇒ Object
19 20 21 22 23 |
# File 'lib/basic_service.rb', line 19 def error(str = '') @error = true = str @pristine = true end |
#success(str = '') ⇒ Object
13 14 15 16 17 |
# File 'lib/basic_service.rb', line 13 def success(str = '') @success = true = str @pristine = true end |
#success? ⇒ Boolean
Defaults to the boolean’ed result of “call”
37 38 39 40 41 |
# File 'lib/basic_service.rb', line 37 def success? raise RuntimeError, "#success or #error should be called inside #call" unless @pristine raise RuntimeError, "both #success and #error where called" if (@success && @error) @success && !@error end |