Module: ProductGroupSearch::CustomFieldStrategy

Defined in:
lib/nimbleshop/product_group_search/custom_field_strategy.rb

Instance Method Summary collapse

Instance Method Details

#custom_fieldObject



18
19
20
# File 'lib/nimbleshop/product_group_search/custom_field_strategy.rb', line 18

def custom_field
  @_custom_field ||= CustomField.find(self.name)
end

#field_typeObject



31
32
33
# File 'lib/nimbleshop/product_group_search/custom_field_strategy.rb', line 31

def field_type
  custom_field.field_type
end

#join(proxy) ⇒ Object



3
4
5
# File 'lib/nimbleshop/product_group_search/custom_field_strategy.rb', line 3

def join(proxy)
  proxy.join(target_table).on(join_condition)
end

#join_conditionObject



7
8
9
# File 'lib/nimbleshop/product_group_search/custom_field_strategy.rb', line 7

def join_condition
  target_table[:product_id].eq(Product.arel_table[:id])
end

#localized_nameObject



35
36
37
# File 'lib/nimbleshop/product_group_search/custom_field_strategy.rb', line 35

def localized_name
  custom_field.name
end

#query_columnObject



22
23
24
25
26
27
28
29
# File 'lib/nimbleshop/product_group_search/custom_field_strategy.rb', line 22

def query_column
  field_type = custom_field.field_type
  if field_type == 'text'
    :value
  else
    "#{field_type}_value".to_sym
  end
end

#target_tableObject



11
12
13
14
15
16
# File 'lib/nimbleshop/product_group_search/custom_field_strategy.rb', line 11

def target_table
  unless @_target
    @_target =CustomFieldAnswer.arel_table.alias("answers#{index}")
  end
  @_target
end