Class: Siftly::FilterConfig
- Inherits:
-
Object
- Object
- Siftly::FilterConfig
show all
- Defined in:
- lib/siftly/filter_config.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(key, settings = {}) ⇒ FilterConfig
Returns a new instance of FilterConfig.
7
8
9
10
|
# File 'lib/siftly/filter_config.rb', line 7
def initialize(key, settings = {})
@key = key.to_sym
@settings = symbolize_keys(settings)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/siftly/filter_config.rb', line 28
def method_missing(method_name, *arguments, &block)
return super if block
method = method_name.to_s
if method.end_with?("=")
@settings[method.delete_suffix("=").to_sym] = arguments.fetch(0)
elsif arguments.empty?
@settings[method_name]
else
super
end
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
5
6
7
|
# File 'lib/siftly/filter_config.rb', line 5
def key
@key
end
|
Instance Method Details
#[](name) ⇒ Object
12
13
14
|
# File 'lib/siftly/filter_config.rb', line 12
def [](name)
@settings[name.to_sym]
end
|
#fetch(name, *fallback) ⇒ Object
16
17
18
|
# File 'lib/siftly/filter_config.rb', line 16
def fetch(name, *fallback)
@settings.fetch(name.to_sym, *fallback)
end
|
#merge(overrides) ⇒ Object
24
25
26
|
# File 'lib/siftly/filter_config.rb', line 24
def merge(overrides)
self.class.new(key, @settings.merge(symbolize_keys(overrides)))
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
42
43
44
|
# File 'lib/siftly/filter_config.rb', line 42
def respond_to_missing?(method_name, include_private = false)
method_name.to_s.end_with?("=") || @settings.key?(method_name.to_sym) || super
end
|
#to_h ⇒ Object
20
21
22
|
# File 'lib/siftly/filter_config.rb', line 20
def to_h
@settings.dup
end
|