Class: Drillbit::Resource::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/drillbit/resource/model.rb

Constant Summary collapse

DEFAULT_PROCESSORS =
%w{filtering sorting paging indexing}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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:, **options)
  self.resource   = resource
  self.parameters = parameters.dup
  self.processors = options.fetch(:processors, DEFAULT_PROCESSORS)
end

Instance Attribute Details

#parametersObject

Returns the value of attribute parameters.



13
14
15
# File 'lib/drillbit/resource/model.rb', line 13

def parameters
  @parameters
end

#processorsObject

Returns the value of attribute processors.



15
16
17
# File 'lib/drillbit/resource/model.rb', line 15

def processors
  @processors
end

#resourceObject

Returns the value of attribute resource.



13
14
15
# File 'lib/drillbit/resource/model.rb', line 13

def resource
  @resource
end

Instance Method Details

#metaObject



29
30
31
32
33
# File 'lib/drillbit/resource/model.rb', line 29

def meta
  @meta ||= processors.inject({}) do |, processor|
    .merge processor.meta(processed, parameters)
  end
end

#processedObject



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