Class: Stall::ProductFilters::BaseFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/stall/product_filters/base_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(products, options = {}) ⇒ BaseFilter

Returns a new instance of BaseFilter.



6
7
8
9
# File 'lib/stall/product_filters/base_filter.rb', line 6

def initialize(products, options = {})
  @products = products
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/stall/product_filters/base_filter.rb', line 4

def options
  @options
end

#productsObject (readonly)

Returns the value of attribute products.



4
5
6
# File 'lib/stall/product_filters/base_filter.rb', line 4

def products
  @products
end

Instance Method Details

#available?Boolean

Can be overriden to hide the filter depending on certain conditions, e.g. there’s more than one option so the filter is useful

Returns:

  • (Boolean)


22
23
24
# File 'lib/stall/product_filters/base_filter.rb', line 22

def available?
  options[:force] || true
end

#keyObject



38
39
40
# File 'lib/stall/product_filters/base_filter.rb', line 38

def key
  @key ||= self.class.name.demodulize.underscore
end

#labelObject



15
16
17
# File 'lib/stall/product_filters/base_filter.rb', line 15

def label
  I18n.t("stall.products.filters.#{ key }")
end

#nameObject



11
12
13
# File 'lib/stall/product_filters/base_filter.rb', line 11

def name
  key.gsub(/_filter/, '')
end

#partial_localsObject



34
35
36
# File 'lib/stall/product_filters/base_filter.rb', line 34

def partial_locals
  { filter: self }
end

#partial_pathObject



30
31
32
# File 'lib/stall/product_filters/base_filter.rb', line 30

def partial_path
  "stall/products/filters/#{ key }"
end

#rendering_options(options = {}) ⇒ Object



26
27
28
# File 'lib/stall/product_filters/base_filter.rb', line 26

def rendering_options(options = {})
  { partial: partial_path, locals: partial_locals }.deep_merge(options)
end