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
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Class Method Details
.sort_keys_select_options ⇒ Object
Class method: returns all database columns as sort options
71 72 73 74 75 |
# File 'app/models/facet.rb', line 71 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
84 85 86 |
# File 'app/models/facet.rb', line 84 def applicable_items Item.by_product_line_id(product_line_ids).by_product_category_id(product_category_ids).order(:sku) end |
#deep_dup ⇒ Object
28 29 30 31 32 |
# File 'app/models/facet.rb', line 28 def deep_dup deep_clone(include: %i[product_lines product_categories]) do |original, copy| copy.name = "#{original.name} (copy)" if copy.is_a?(Facet) end end |
#product_categories ⇒ ActiveRecord::Relation<ProductCategory>
22 |
# File 'app/models/facet.rb', line 22 has_and_belongs_to_many :product_categories |
#product_lines ⇒ ActiveRecord::Relation<ProductLine>
21 |
# File 'app/models/facet.rb', line 21 has_and_belongs_to_many :product_lines |
#refresh_specs(token: nil, items: nil) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'app/models/facet.rb', line 88 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
78 79 80 81 82 |
# File 'app/models/facet.rb', line 78 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
57 58 59 |
# File 'app/models/facet.rb', line 57 def to_s "#{name} [#{id}]" end |
#tokens ⇒ Object
61 62 63 |
# File 'app/models/facet.rb', line 61 def tokens grouping_spec_tokens.filter_map(&:presence) end |
#tokens_select_options ⇒ Object
Provide a sorted list respecting the selected order
66 67 68 |
# File 'app/models/facet.rb', line 66 def tokens | ProductSpecification. end |