Class: FilterFactory::Filter
- Inherits:
-
Object
- Object
- FilterFactory::Filter
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion
- Defined in:
- lib/filter_factory/filter.rb
Defined Under Namespace
Classes: DuplicateFieldError
Constant Summary
collapse
- CONDITIONS =
[:eq, :ne, :lt, :lte, :gt, :gte, :all, :in, :nin, :regex, :exists, :presents].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
12
13
14
|
# File 'lib/filter_factory/filter.rb', line 12
def initialize
@fields = []
end
|
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
8
9
10
|
# File 'lib/filter_factory/filter.rb', line 8
def fields
@fields
end
|
Class Method Details
.create(&block) ⇒ Object
49
50
51
|
# File 'lib/filter_factory/filter.rb', line 49
def create(&block)
new.tap { |filter| filter.instance_eval &block }
end
|
Instance Method Details
#attributes ⇒ Object
16
17
18
19
20
21
|
# File 'lib/filter_factory/filter.rb', line 16
def attributes
@fields.inject(HashWithIndifferentAccess.new) do |acc, field|
acc[field.alias] = field.value
acc
end
end
|
#attributes=(attributes = {}) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/filter_factory/filter.rb', line 23
def attributes=(attributes = {})
return unless attributes
attributes.each do |name, value|
public_send("#{name}=", value)
end
end
|
#filled_fields ⇒ Object
30
31
32
|
# File 'lib/filter_factory/filter.rb', line 30
def filled_fields
fields.select { |f| !f.value.nil? && f.value != '' }
end
|
#get_field(name) ⇒ Object
34
35
36
|
# File 'lib/filter_factory/filter.rb', line 34
def get_field(name)
fields.find { |f| f.name == name }
end
|
#persisted? ⇒ Boolean
38
39
40
|
# File 'lib/filter_factory/filter.rb', line 38
def persisted?
false
end
|