Class: Super::Filter::FormObject::FilterFormField

Inherits:
Object
  • Object
show all
Defined in:
lib/super/filter/form_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(humanized_field_name:, field_name:, type:, params:) ⇒ FilterFormField

Returns a new instance of FilterFormField.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/super/filter/form_object.rb', line 7

def initialize(humanized_field_name:, field_name:, type:, params:)
  @humanized_field_name = humanized_field_name
  @field_name = field_name
  @field_type = type
  @params = params
  @specified_values =
    type.q
      .map do |query_field_name|
        [
          query_field_name,
          (params || {})[query_field_name],
        ]
      end
      .to_h

  @specified_values.each do |key, value|
    define_singleton_method(key) { value }
  end
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



28
29
30
# File 'lib/super/filter/form_object.rb', line 28

def field_name
  @field_name
end

#field_typeObject (readonly)

Returns the value of attribute field_type.



29
30
31
# File 'lib/super/filter/form_object.rb', line 29

def field_type
  @field_type
end

#humanized_field_nameObject (readonly)

Returns the value of attribute humanized_field_name.



27
28
29
# File 'lib/super/filter/form_object.rb', line 27

def humanized_field_name
  @humanized_field_name
end

#specified_valuesObject (readonly)

Returns the value of attribute specified_values.



30
31
32
# File 'lib/super/filter/form_object.rb', line 30

def specified_values
  @specified_values
end

Instance Method Details

#opObject



32
33
34
# File 'lib/super/filter/form_object.rb', line 32

def op
  (@params || {})[:op]
end

#operatorsObject



36
37
38
39
40
# File 'lib/super/filter/form_object.rb', line 36

def operators
  @field_type.operators
    .map { |o| [o.name, o.identifier] }
    .to_h
end

#to_partial_pathObject



42
43
44
# File 'lib/super/filter/form_object.rb', line 42

def to_partial_path
  @field_type.to_partial_path
end