Class: Facet
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Facet
- Includes:
- Models::Auditable
- Defined in:
- app/models/facet.rb
Overview
== Schema Information
Table name: facets
Database name: primary
id :integer not null, primary key
description :string
grouping_spec_tokens :string default([]), is an Array
name :string
product_category_ids :string
product_line_ids :string
sort_keys :string default(["price asc", "item_sku asc"]), is an Array
use_product_picture :boolean default(FALSE), not null
created_at :datetime not null
updated_at :datetime not null
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Has and belongs to many collapse
- #product_categories ⇒ ActiveRecord::Relation<ProductCategory>
- #product_lines ⇒ ActiveRecord::Relation<ProductLine>
Class Method Summary collapse
-
.sort_keys_select_options ⇒ Object
Class method: returns all database columns as sort options.
Instance Method Summary collapse
- #applicable_items ⇒ Object
- #deep_dup ⇒ Object
- #refresh_specs(token: nil, items: nil) ⇒ Object
-
#sort_keys_select_options ⇒ Object
Instance method: returns sort options with this facet's grouping tokens prioritized.
- #to_s ⇒ Object
- #tokens ⇒ Object
-
#tokens_select_options ⇒ Object
Provide a sorted list respecting the selected order.
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Class Method Details
.sort_keys_select_options ⇒ Object
Class method: returns all database columns as sort options
72 73 74 75 76 |
# File 'app/models/facet.rb', line 72 def self. = ViewProductCatalog.columns.map(&:name).sort.flat_map { |n| ["#{n} asc", "#{n} desc"] } = ProductSpecification..flat_map { |t| ["spec:#{t} asc", "spec:#{t} desc"] } + end |
Instance Method Details
#applicable_items ⇒ Object
85 86 87 |
# File 'app/models/facet.rb', line 85 def applicable_items Item.by_product_line_id(product_line_ids).by_product_category_id(product_category_ids).order(:sku) end |
#deep_dup ⇒ Object
27 28 29 30 31 |
# File 'app/models/facet.rb', line 27 def deep_dup deep_clone(include: [:product_lines, :product_categories]) do |original, copy| copy.name = "#{original.name} (copy)" if copy.is_a?(Facet) end end |
#product_categories ⇒ ActiveRecord::Relation<ProductCategory>
21 |
# File 'app/models/facet.rb', line 21 has_and_belongs_to_many :product_categories |
#product_lines ⇒ ActiveRecord::Relation<ProductLine>
20 |
# File 'app/models/facet.rb', line 20 has_and_belongs_to_many :product_lines |
#refresh_specs(token: nil, items: nil) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'app/models/facet.rb', line 89 def refresh_specs(token: nil, items: nil) tokens = ([token].compact.presence || grouping_spec_tokens).map(&:to_sym) (items || applicable_items).each do |item| item.update_rendered_product_specifications(tokens: tokens) end # Also touch product line product_lines.each(&:purge_edge_cache) end |
#sort_keys_select_options ⇒ Object
Instance method: returns sort options with this facet's grouping tokens prioritized
79 80 81 82 83 |
# File 'app/models/facet.rb', line 79 def # Place this facet's grouping tokens at the top = tokens.flat_map { |t| ["spec:#{t} asc", "spec:#{t} desc"] } | self.class. end |
#to_s ⇒ Object
58 59 60 |
# File 'app/models/facet.rb', line 58 def to_s "#{name} [#{id}]" end |
#tokens ⇒ Object
62 63 64 |
# File 'app/models/facet.rb', line 62 def tokens grouping_spec_tokens.map(&:presence).compact end |
#tokens_select_options ⇒ Object
Provide a sorted list respecting the selected order
67 68 69 |
# File 'app/models/facet.rb', line 67 def tokens | ProductSpecification. end |