Class: Drillbit::Resource::Model
- Inherits:
-
Object
- Object
- Drillbit::Resource::Model
- Defined in:
- lib/drillbit/resource/model.rb
Constant Summary collapse
- DEFAULT_PROCESSORS =
%w{filtering sorting paging indexing}.freeze
Instance Attribute Summary collapse
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#processors ⇒ Object
Returns the value of attribute processors.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource:, parameters:, **options) ⇒ Model
constructor
A new instance of Model.
- #meta ⇒ Object
- #processed ⇒ Object
Constructor Details
#initialize(resource:, parameters:, **options) ⇒ Model
Returns a new instance of Model.
17 18 19 20 21 |
# File 'lib/drillbit/resource/model.rb', line 17 def initialize(resource:, parameters:, **) self.resource = resource self.parameters = parameters.dup self.processors = .fetch(:processors, DEFAULT_PROCESSORS) end |
Instance Attribute Details
#parameters ⇒ Object
Returns the value of attribute parameters.
13 14 15 |
# File 'lib/drillbit/resource/model.rb', line 13 def parameters @parameters end |
#processors ⇒ Object
Returns the value of attribute processors.
15 16 17 |
# File 'lib/drillbit/resource/model.rb', line 15 def processors @processors end |
#resource ⇒ Object
Returns the value of attribute resource.
13 14 15 |
# File 'lib/drillbit/resource/model.rb', line 13 def resource @resource end |
Instance Method Details
#meta ⇒ Object
29 30 31 32 33 |
# File 'lib/drillbit/resource/model.rb', line 29 def @meta ||= processors.inject({}) do |, processor| .merge processor.(processed, parameters) end end |
#processed ⇒ Object
23 24 25 26 27 |
# File 'lib/drillbit/resource/model.rb', line 23 def processed @processed ||= processors.inject(resource) do |processed_resource, processor| processor.processed(processed_resource, parameters) end end |