Class: Super::Filter::FormObject::AttributeForm

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, field_name:, operators:, params:) ⇒ AttributeForm

Returns a new instance of AttributeForm.



7
8
9
10
11
12
# File 'lib/super/filter/form_object.rb', line 7

def initialize(model:, field_name:, operators:, params:)
  @model = model
  @field_name = field_name
  @operators = operators
  @params = params || {}
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



15
16
17
# File 'lib/super/filter/form_object.rb', line 15

def field_name
  @field_name
end

#modelObject (readonly)

Returns the value of attribute model.



14
15
16
# File 'lib/super/filter/form_object.rb', line 14

def model
  @model
end

#operatorsObject (readonly)

Returns the value of attribute operators.



16
17
18
# File 'lib/super/filter/form_object.rb', line 16

def operators
  @operators
end

#paramsObject (readonly)

Returns the value of attribute params.



17
18
19
# File 'lib/super/filter/form_object.rb', line 17

def params
  @params
end

Instance Method Details

#each_operatorObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/super/filter/form_object.rb', line 19

def each_operator
  return enum_for(:each_operator) if !block_given?

  @operators.each do |operator|
    operator_form = OperatorForm.new(
      operator: operator,
      params: @params[operator.identifier]
    )

    yield(operator_form)
  end
end

#humanized_attribute_nameObject



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

def humanized_attribute_name
  @model.human_attribute_name(@field_name)
end