Class: WithFilters::FilterForm

Inherits:
Object
  • Object
show all
Defined in:
lib/with_filters/models/filter_form.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FilterForm) initialize(records, values = {}, options = {})

Returns a new instance of FilterForm

See Also:

Since:

  • 0.1.0



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 = {}, options = {})
  @records = records
  @values  = values

  @theme = options.delete(:theme)
  @attrs = options.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

- (Object) actions (readonly)

Returns the value of attribute actions



3
4
5
# File 'lib/with_filters/models/filter_form.rb', line 3

def actions
  @actions
end

- (Object) attrs (readonly)

Returns the value of attribute attrs



3
4
5
# File 'lib/with_filters/models/filter_form.rb', line 3

def attrs
  @attrs
end

- (Object) filters (readonly)

Returns the value of attribute filters



3
4
5
# File 'lib/with_filters/models/filter_form.rb', line 3

def filters
  @filters
end

- (Object) hidden_filters (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

- (Object) param_namespace (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

- (Object) to_partial_path (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

- (Object) action(type, options = {})

Parameters:

  • type (Symbol)
  • options (Hash) (defaults to: {})

Since:

  • 0.1.0



60
61
62
# File 'lib/with_filters/models/filter_form.rb', line 60

def action(type, options = {})
  @actions.push(WithFilters::Action.new(type, options))
end

- (Object) hidden(name, options = {})

See Also:

  • input

Since:

  • 0.1.0



25
26
27
28
29
# File 'lib/with_filters/models/filter_form.rb', line 25

def hidden(name, options = {})
  options.merge!(as: :hidden)

  input(name, options)
end

- (Object) input(name, options = {})

Parameters:

  • name (Symbol)
  • options (Hash) (defaults to: {})

Since:

  • 0.1.0



35
36
37
38
39
40
41
42
43
# File 'lib/with_filters/models/filter_form.rb', line 35

def input(name, options = {})
  options[:as] = find_as(name, options[:collection]) unless options[:as]
  options.merge!(theme: @theme)
  as = options[:as]

  filter = WithFilters::Filter.create(name, self.param_namespace, @values[name.to_s], options)

  (as == :hidden ? @hidden_filters : @filters).push(filter)
end

- (Object) input_range(name, options = {})

Parameters:

  • name (Symbol)
  • options (Hash) (defaults to: {})

Since:

  • 0.1.0



49
50
51
52
53
54
# File 'lib/with_filters/models/filter_form.rb', line 49

def input_range(name, options = {})
  options[:as] = find_as(name, options[:collection]) unless options[:as]
  options.merge!(theme: @theme)

  @filters.push(WithFilters::Filter.create_range(name, self.param_namespace, @values[name.to_s] || {}, options))
end