Class: Wallaby::ModelServicer
- Inherits:
-
Object
- Object
- Wallaby::ModelServicer
- Defined in:
- lib/services/wallaby/model_servicer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #collection(params, ability) ⇒ Object
- #create(params, ability) ⇒ Object
- #destroy(resource, params) ⇒ Object
- #find(id, params) ⇒ Object
-
#initialize(model_class = nil, model_decorator = nil) ⇒ ModelServicer
constructor
A new instance of ModelServicer.
- #new(params) ⇒ Object
- #update(resource, params, ability) ⇒ Object
Constructor Details
#initialize(model_class = nil, model_decorator = nil) ⇒ ModelServicer
Returns a new instance of ModelServicer.
8 9 10 11 12 13 |
# File 'lib/services/wallaby/model_servicer.rb', line 8 def initialize(model_class = nil, model_decorator = nil) @model_class = model_class || self.class.model_class fail ArgumentError, 'model class required' unless @model_class @model_decorator = model_decorator || Wallaby::DecoratorFinder.find_model(@model_class) @delegator = Wallaby.adaptor.model_operator.new @model_class, @model_decorator end |
Class Method Details
.model_class ⇒ Object
2 3 4 5 6 |
# File 'lib/services/wallaby/model_servicer.rb', line 2 def self.model_class if self < Wallaby::ModelServicer Wallaby::Utils.to_model_class name.gsub('Servicer', ''), name end end |
Instance Method Details
#collection(params, ability) ⇒ Object
15 16 17 |
# File 'lib/services/wallaby/model_servicer.rb', line 15 def collection(params, ability) @delegator.collection params, ability end |
#create(params, ability) ⇒ Object
27 28 29 |
# File 'lib/services/wallaby/model_servicer.rb', line 27 def create(params, ability) @delegator.create params, ability end |
#destroy(resource, params) ⇒ Object
35 36 37 |
# File 'lib/services/wallaby/model_servicer.rb', line 35 def destroy(resource, params) @delegator.destroy resource, params end |
#find(id, params) ⇒ Object
23 24 25 |
# File 'lib/services/wallaby/model_servicer.rb', line 23 def find(id, params) @delegator.find id, params end |
#new(params) ⇒ Object
19 20 21 |
# File 'lib/services/wallaby/model_servicer.rb', line 19 def new(params) @delegator.new params end |
#update(resource, params, ability) ⇒ Object
31 32 33 |
# File 'lib/services/wallaby/model_servicer.rb', line 31 def update(resource, params, ability) @delegator.update resource, params, ability end |