Class: Dorsale::SmallData::Filter
- Inherits:
-
Object
- Object
- Dorsale::SmallData::Filter
show all
- Defined in:
- app/filters/dorsale/small_data/filter.rb
Instance Method Summary
collapse
Constructor Details
#initialize(jar) ⇒ Filter
Returns a new instance of Filter.
2
3
4
|
# File 'app/filters/dorsale/small_data/filter.rb', line 2
def initialize(jar)
@jar = jar
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'app/filters/dorsale/small_data/filter.rb', line 42
def method_missing(method, *args)
key = method.to_s
if strategies.key?(key)
get(key)
else
super
end
end
|
Instance Method Details
#apply(query) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/filters/dorsale/small_data/filter.rb', line 30
def apply(query)
strategies.each do |key, strategy|
value = get(key)
next if value.blank?
query = strategy.apply(query, value)
end
return query
end
|
#get(key) ⇒ Object
16
17
18
|
# File 'app/filters/dorsale/small_data/filter.rb', line 16
def get(key)
read[key.to_s]
end
|
#read ⇒ Object
10
11
12
13
14
|
# File 'app/filters/dorsale/small_data/filter.rb', line 10
def read
JSON.parse @jar["filters"].to_s
rescue JSON::ParserError
{}
end
|
#set(key, value) ⇒ Object
20
21
22
23
24
|
# File 'app/filters/dorsale/small_data/filter.rb', line 20
def set(key, value)
array = read
array[key.to_s] = value
store(array)
end
|
#store(filters) ⇒ Object
6
7
8
|
# File 'app/filters/dorsale/small_data/filter.rb', line 6
def store(filters)
@jar["filters"] = filters.to_json
end
|
#strategies ⇒ Object
26
27
28
|
# File 'app/filters/dorsale/small_data/filter.rb', line 26
def strategies
self.class::STRATEGIES
end
|