Class: Siftly::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/siftly/filter.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}) ⇒ Filter

Returns a new instance of Filter.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/siftly/filter.rb', line 13

def initialize(config: {})
  @config =
    case config
    when FilterConfig
      config.merge({})
    when Hash
      FilterConfig.new(self.class.key || :unknown, config)
    else
      raise ConfigurationError, "filter config must be a Hash or FilterConfig"
    end
end

Class Attribute Details

.keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/siftly/filter.rb', line 6

def key
  @key
end

Class Method Details

.register_as(key) ⇒ Object



8
9
10
# File 'lib/siftly/filter.rb', line 8

def register_as(key)
  @key = key.to_sym
end

Instance Method Details

#call(value:, attribute: nil, record: nil, context: {}) ⇒ Object

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/siftly/filter.rb', line 25

def call(value:, attribute: nil, record: nil, context: {})
  raise NotImplementedError, "#{self.class} must implement #call"
end