Class: Wallaby::Her::ModelServiceProvider
- Inherits:
-
ModelServiceProvider
- Object
- ModelServiceProvider
- Wallaby::Her::ModelServiceProvider
- Defined in:
- lib/adapters/wallaby/her/model_service_provider.rb
Overview
Model service provider for HER ORM
Instance Method Summary collapse
-
#collection(_params, _authorizer) ⇒ ActiveRecord::Relation
No general practices of how ordering and searching can be done in Her.
- #create(resource, params, authorizer) ⇒ Object
- #destroy(resource, _params, _authorizer) ⇒ Object
- #find(id, _params, _authorizer) ⇒ Object
- #new(_params, _authorizer) ⇒ Object
-
#paginate(query, _params) ⇒ ActiveRecord::Relation
No general practices of how pagination can be done in Her.
-
#permit(params, action, authorizer) ⇒ ActionController::Parameters
Only the general fields will be permitted.
- #update(resource, params, authorizer) ⇒ Object
Instance Method Details
#collection(_params, _authorizer) ⇒ ActiveRecord::Relation
No general practices of how ordering and searching can be done in Her. Therefore, it will just return all
NOTE: pagination free here. Since somewhere might need the collection without any pagination
26 27 28 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 26 def collection(_params, ) @model_class.all end |
#create(resource, params, authorizer) ⇒ Object
58 59 60 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 58 def create(resource, params, ) save __callee__, resource, params, end |
#destroy(resource, _params, _authorizer) ⇒ Object
72 73 74 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 72 def destroy(resource, _params, ) resource.destroy end |
#find(id, _params, _authorizer) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 48 def find(id, _params, ) resource = @model_class.find id raise ResourceNotFound, id unless resource resource end |
#new(_params, _authorizer) ⇒ Object
42 43 44 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 42 def new(_params, ) @model_class.new end |
#paginate(query, _params) ⇒ ActiveRecord::Relation
No general practices of how pagination can be done in Her. Therefore, it will just return all
37 38 39 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 37 def paginate(query, _params) query.all end |
#permit(params, action, authorizer) ⇒ ActionController::Parameters
Only the general fields will be permitted. It’s less possible to guess what nested attributes should be permitted.
12 13 14 15 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 12 def permit(params, action, ) = .permit_params action, @model_class params.require(param_key).permit( || permitted_fields) end |
#update(resource, params, authorizer) ⇒ Object
65 66 67 |
# File 'lib/adapters/wallaby/her/model_service_provider.rb', line 65 def update(resource, params, ) save __callee__, resource, params, end |