Class: Puffer::Filters
- Inherits:
-
Object
show all
- Extended by:
- ActiveModel::Naming, ActiveModel::Translation, ClassMethods
- Includes:
- ActiveModel::AttributeMethods, ActiveModel::Conversion
- Defined in:
- lib/puffer/filters.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary
collapse
controller_filters, model_name
Constructor Details
#initialize(attributes = {}) ⇒ Filters
Returns a new instance of Filters.
10
11
12
13
14
15
|
# File 'lib/puffer/filters.rb', line 10
def initialize attributes = {}
attributes ||= {}
attributes.each do |(key, value)|
send("#{key}=", value) if respond_to?("#{key}=")
end
end
|
Instance Method Details
#any? ⇒ Boolean
29
30
31
|
# File 'lib/puffer/filters.rb', line 29
def any?
attributes.keys.any? { |attribute| !send(attribute).nil? }
end
|
#conditions ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/puffer/filters.rb', line 33
def conditions
attributes.except('puffer_search', 'puffer_order').keys.reduce({}) do |res, attribute|
value = send(attribute)
unless value.nil?
value = case value
when 'puffer_nil' then nil
when 'puffer_blank' then ''
else value
end
res[attribute] = value
end
res
end
end
|
#order ⇒ Object
54
55
56
|
# File 'lib/puffer/filters.rb', line 54
def order
puffer_order
end
|
#persisted? ⇒ Boolean
25
26
27
|
# File 'lib/puffer/filters.rb', line 25
def persisted?
false
end
|
#read_attribute(name) ⇒ Object
17
18
19
|
# File 'lib/puffer/filters.rb', line 17
def read_attribute name
attributes[name]
end
|
#search ⇒ Object
50
51
52
|
# File 'lib/puffer/filters.rb', line 50
def search
puffer_search
end
|
#write_attribute(name, value) ⇒ Object
21
22
23
|
# File 'lib/puffer/filters.rb', line 21
def write_attribute name, value
attributes[name] = value.presence if attributes.key?(name)
end
|