Class: WithFilters::FilterForm
- Inherits:
-
Object
- Object
- WithFilters::FilterForm
- Defined in:
- lib/with_filters/models/filter_form.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#hidden_filters ⇒ Object
readonly
Returns the value of attribute hidden_filters.
-
#param_namespace ⇒ Object
readonly
Returns the value of attribute param_namespace.
-
#to_partial_path ⇒ Object
readonly
Returns the value of attribute to_partial_path.
Instance Method Summary collapse
- #action(type, options = {}) ⇒ Object
- #hidden(name, options = {}) ⇒ Object
-
#initialize(records, values = {}, options = {}) ⇒ FilterForm
constructor
A new instance of FilterForm.
- #input(name, options = {}) ⇒ Object
- #input_range(name, options = {}) ⇒ Object
Constructor Details
#initialize(records, values = {}, options = {}) ⇒ FilterForm
Returns a new instance of FilterForm.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/with_filters/models/filter_form.rb', line 8 def initialize(records, values = {}, = {}) @records = records @values = values @theme = .delete(:theme) @attrs = .reverse_merge(novalidate: 'novalidate', method: 'get') @to_partial_path = self.class.name.underscore @param_namespace = @records.with_filters_data[:param_namespace] @hidden_filters = [] @filters = [] @actions = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
3 4 5 |
# File 'lib/with_filters/models/filter_form.rb', line 3 def actions @actions end |
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'lib/with_filters/models/filter_form.rb', line 3 def attrs @attrs end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
3 4 5 |
# File 'lib/with_filters/models/filter_form.rb', line 3 def filters @filters end |
#hidden_filters ⇒ Object (readonly)
Returns the value of attribute hidden_filters.
3 4 5 |
# File 'lib/with_filters/models/filter_form.rb', line 3 def hidden_filters @hidden_filters end |
#param_namespace ⇒ Object (readonly)
Returns the value of attribute param_namespace.
3 4 5 |
# File 'lib/with_filters/models/filter_form.rb', line 3 def param_namespace @param_namespace end |
#to_partial_path ⇒ Object (readonly)
Returns the value of attribute to_partial_path.
3 4 5 |
# File 'lib/with_filters/models/filter_form.rb', line 3 def to_partial_path @to_partial_path end |
Instance Method Details
#action(type, options = {}) ⇒ Object
60 61 62 |
# File 'lib/with_filters/models/filter_form.rb', line 60 def action(type, = {}) @actions.push(WithFilters::Action.new(type, )) end |
#hidden(name, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/with_filters/models/filter_form.rb', line 25 def hidden(name, = {}) .merge!(as: :hidden) input(name, ) end |
#input(name, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/with_filters/models/filter_form.rb', line 35 def input(name, = {}) [:as] = find_as(name, [:collection]) unless [:as] .merge!(theme: @theme) as = [:as] filter = WithFilters::Filter.create(name, self.param_namespace, @values[name], ) (as == :hidden ? @hidden_filters : @filters).push(filter) end |
#input_range(name, options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/with_filters/models/filter_form.rb', line 49 def input_range(name, = {}) [:as] = find_as(name, [:collection]) unless [:as] .merge!(theme: @theme) @filters.push(WithFilters::Filter.create_range(name, self.param_namespace, @values[name] || {}, )) end |