Class: Upframework::BaseService
- Inherits:
-
Object
- Object
- Upframework::BaseService
- Defined in:
- app/services/upframework/base_service.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
- #error? ⇒ Boolean
- #error_messages ⇒ Object
- #execute ⇒ Object
-
#initialize(**attributes) ⇒ BaseService
constructor
A new instance of BaseService.
- #post_initialize(**attributes) ⇒ Object
- #result ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(**attributes) ⇒ BaseService
Returns a new instance of BaseService.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/services/upframework/base_service.rb', line 12 def initialize(**attributes) @errors = [] self.class.send(:attr_reader, *attributes.keys) #TODO: Remove. This should be handled on the child class. attributes.each do |key, value| instance_variable_set("@#{key}", value) end post_initialize(**attributes) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'app/services/upframework/base_service.rb', line 3 def errors @errors end |
Class Method Details
.run(attributes = {}) ⇒ Object
6 7 8 9 |
# File 'app/services/upframework/base_service.rb', line 6 def run(attributes = {}) attributes = Hash[attributes.to_h.map { |k, v| [k.to_sym, v] }] new(**attributes).tap(&:execute) end |
Instance Method Details
#error? ⇒ Boolean
38 39 40 |
# File 'app/services/upframework/base_service.rb', line 38 def error? @errors.present? end |
#error_messages ⇒ Object
42 43 44 |
# File 'app/services/upframework/base_service.rb', line 42 def @errors.join('. ') end |
#execute ⇒ Object
28 29 |
# File 'app/services/upframework/base_service.rb', line 28 def execute end |
#post_initialize(**attributes) ⇒ Object
25 26 |
# File 'app/services/upframework/base_service.rb', line 25 def post_initialize(**attributes) end |
#result ⇒ Object
31 32 |
# File 'app/services/upframework/base_service.rb', line 31 def result end |
#success? ⇒ Boolean
34 35 36 |
# File 'app/services/upframework/base_service.rb', line 34 def success? @errors.blank? end |