Class: Drillbit::Resource::Processors::Filtering

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, parameters = {}) ⇒ Filtering

rubocop:disable Style/OptionHash



13
14
15
16
# File 'lib/drillbit/resource/processors/filtering.rb', line 13

def initialize(resource, parameters = {})
  self.resource   = resource
  self.parameters = Parameters::Filter.new(parameters['filter'] || {})
end

Instance Attribute Details

#parametersObject

Returns the value of attribute parameters.



9
10
11
# File 'lib/drillbit/resource/processors/filtering.rb', line 9

def parameters
  @parameters
end

#resourceObject

Returns the value of attribute resource.



9
10
11
# File 'lib/drillbit/resource/processors/filtering.rb', line 9

def resource
  @resource
end

Class Method Details

.meta(*_attrs) ⇒ Object



23
24
25
# File 'lib/drillbit/resource/processors/filtering.rb', line 23

def self.meta(*_attrs)
  {}
end

.processed(*attrs) ⇒ Object

rubocop:enable Style/OptionHash



19
20
21
# File 'lib/drillbit/resource/processors/filtering.rb', line 19

def self.processed(*attrs)
  new(*attrs).processed
end

Instance Method Details

#processedObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/drillbit/resource/processors/filtering.rb', line 27

def processed
  parameters.each_with_object(resource) do |name, value, filtered_resource|
    filter_method = filter_method_for(name)

    if !filter_method
      filtered_resource
    elsif filter_method.arity.zero?
      filtered_resource.public_send(filter_method.name)
    else
      filtered_resource.public_send(filter_method.name, value)
    end
  end
end