Class: ObjectServices::Base
- Inherits:
-
Object
- Object
- ObjectServices::Base
- Defined in:
- lib/object_services/base.rb
Defined Under Namespace
Classes: ServiceError
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#create(params) ⇒ Boolean
Create a record with a given param object.
-
#destroy ⇒ Boolean
Destroys the service’s model and clears it.
-
#initialize(model) ⇒ Base
constructor
:nodoc:.
-
#update(params) ⇒ Boolean
Update the service’s model with a given param object.
Constructor Details
#initialize(model) ⇒ Base
:nodoc:
10 11 12 13 |
# File 'lib/object_services/base.rb', line 10 def initialize(model) @model = model @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'lib/object_services/base.rb', line 3 def errors @errors end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/object_services/base.rb', line 3 def model @model end |
Instance Method Details
#create(params) ⇒ Boolean
Create a record with a given param object
25 26 27 |
# File 'lib/object_services/base.rb', line 25 def create(params) update_model(params) end |
#destroy ⇒ Boolean
Destroys the service’s model and clears it
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/object_services/base.rb', line 31 def destroy if @model.present? @model.destroy @model = nil true else @errors << self.class.model_not_found return false end end |
#update(params) ⇒ Boolean
Update the service’s model with a given param object
18 19 20 |
# File 'lib/object_services/base.rb', line 18 def update(params) update_model(params) end |