Class: RoomType
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RoomType
- Defined in:
- app/models/room_type.rb
Overview
== Schema Information
Table name: room_types
Database name: primary
id :integer not null, primary key
environment :string(50)
friendly_name :string
name :string(32) not null
parent_room :string
seo_key :string
tire_tracks_option :boolean
Indexes
idx_environment (environment)
index_room_types_on_name (name)
index_room_types_on_seo_key (seo_key)
Constant Summary collapse
- ROOM_ICON_FILE_BASENAME_BY_RT_ID =
Room icon file basename by rt id.
{ '2' => 'bathroom', '4' => 'bedroom', '10' => 'kitchen', '1' => 'basement', '22' => 'basement', '18' => 'other-room', '20' => 'driveway', '21' => 'crosswalk', '29' => 'tiles', '23' => 'patio-chair' }.freeze
- MINIMUM_SQFT_FOR_IQ =
Minimum sqft for iq.
{ indoor: 2.6, outdoor: 10.0 }.freeze
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Validates the room type name is present.
Has many collapse
-
#heating_element_product_line_options ⇒ ActiveRecord::Relation<HeatingElementProductLineOption>
Heating-element product line options available for this room type.
-
#showcases ⇒ ActiveRecord::Relation<Showcase>
Showcases featuring this room type.
Has and belongs to many collapse
-
#design_tool_fixtures ⇒ ActiveRecord::Relation<DesignToolFixture>
Design tool fixtures available for this room type.
-
#stores ⇒ ActiveRecord::Relation<Store>
Stores offering this room type.
Class Method Summary collapse
-
.by_environment ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by environment.
-
.by_name ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by name.
-
.grouped_by_environment_for_select(is_public = nil) ⇒ Hash{String => Array<Array(String, Integer)>}
Room types grouped by environment for grouped select dropdowns.
-
.indoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoor.
-
.indoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoors.
-
.options_by_environment_cached(environment) ⇒ Array<Hash{Symbol => String}>
Cached room type options for quote builder (by seo_key and name).
-
.options_for_select(ev = nil, parameterize = false) ⇒ Array<Array(String, Object)>
[label, value]pairs of room types for select dropdowns. -
.outdoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoor.
-
.outdoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoors.
Instance Method Summary collapse
-
#is_indoor? ⇒ Boolean
Whether this is an indoor room type.
-
#is_outdoor? ⇒ Boolean
Whether this is an outdoor room type.
-
#minimum_sqft_for_iq ⇒ Float
Minimum room square footage required for an Instant Quote, by environment.
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#name ⇒ Object (readonly)
Validates the room type name is present.
Validations:
41 |
# File 'app/models/room_type.rb', line 41 validates :name, presence: true |
Class Method Details
.by_environment ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by environment. Active Record Scope
38 |
# File 'app/models/room_type.rb', line 38 scope :by_environment, ->(ev) { where(environment: ev).by_name } |
.by_name ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by name. Active Record Scope
33 |
# File 'app/models/room_type.rb', line 33 scope :by_name, -> { order(:name) } |
.grouped_by_environment_for_select(is_public = nil) ⇒ Hash{String => Array<Array(String, Integer)>}
Room types grouped by environment for grouped select dropdowns.
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/room_type.rb', line 110 def self.grouped_by_environment_for_select(is_public = nil) if is_public envs = HeatingElementProductLineOption.(is_public: true).distinct.pluck(:environment) rts = RoomType.by_environment(envs).to_a else rts = RoomType.all end rt_by_env = rts.group_by(&:environment) rt_by_env.each do |k, v| rt_by_env[k] = v.map { |r| [r.name, r.id] } end rt_by_env end |
.indoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoor. Active Record Scope
36 |
# File 'app/models/room_type.rb', line 36 scope :indoor, -> { where(environment: 'Indoor').by_name } |
.indoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoors. Active Record Scope
34 |
# File 'app/models/room_type.rb', line 34 scope :indoors, -> { where(environment: 'Indoor').by_name } |
.options_by_environment_cached(environment) ⇒ Array<Hash{Symbol => String}>
Cached room type options for quote builder (by seo_key and name).
Only a non-empty result is cached. A transient empty read (a cold DB
mid-branch/restore, or a request racing ahead of seeding) must not be
written, or it poisons the cache for the full hour — every quote in that
environment then renders a blank "Application Type" dropdown and freezes
room_type_options: [] into the shared RhcParamSet. (Rails.cache.fetch
with skip_nil is not honored by every store, so cache explicitly.)
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/room_type.rb', line 93 def self.(environment) cache_key = ['room_type_options', environment] cached = Rails.cache.read(cache_key) return cached if cached.present? = select(:name, :seo_key) .where(environment:) .pluck(:seo_key, :name) .sort_by { |rt| rt[1] } .map { |rt| { key: rt[0], value: rt[1] } } Rails.cache.write(cache_key, , expires_in: 1.hour) if .present? end |
.options_for_select(ev = nil, parameterize = false) ⇒ Array<Array(String, Object)>
[label, value] pairs of room types for select dropdowns.
73 74 75 76 77 78 79 80 81 |
# File 'app/models/room_type.rb', line 73 def self.(ev = nil, parameterize = false) res = order(:name) res = res.by_environment(ev) if ev.present? if parameterize res.map { |f| [f.name, f.name.parameterize] } else res.map { |f| [f.name, f.id] } end end |
.outdoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoor. Active Record Scope
37 |
# File 'app/models/room_type.rb', line 37 scope :outdoor, -> { where(environment: 'Outdoor').by_name } |
.outdoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoors. Active Record Scope
35 |
# File 'app/models/room_type.rb', line 35 scope :outdoors, -> { where(environment: 'Outdoor').by_name } |
Instance Method Details
#design_tool_fixtures ⇒ ActiveRecord::Relation<DesignToolFixture>
Design tool fixtures available for this room type.
29 |
# File 'app/models/room_type.rb', line 29 has_and_belongs_to_many :design_tool_fixtures |
#heating_element_product_line_options ⇒ ActiveRecord::Relation<HeatingElementProductLineOption>
Heating-element product line options available for this room type.
24 |
# File 'app/models/room_type.rb', line 24 has_many :heating_element_product_line_options, inverse_of: :room_type |
#is_indoor? ⇒ Boolean
Whether this is an indoor room type.
59 60 61 |
# File 'app/models/room_type.rb', line 59 def is_indoor? environment == 'Indoor' end |
#is_outdoor? ⇒ Boolean
Whether this is an outdoor room type.
65 66 67 |
# File 'app/models/room_type.rb', line 65 def is_outdoor? environment == 'Outdoor' end |
#minimum_sqft_for_iq ⇒ Float
Minimum room square footage required for an Instant Quote, by environment.
51 52 53 54 55 |
# File 'app/models/room_type.rb', line 51 def minimum_sqft_for_iq env_sym = :indoor env_sym = environment.to_s.downcase.to_sym if environment.present? MINIMUM_SQFT_FOR_IQ[env_sym] end |
#showcases ⇒ ActiveRecord::Relation<Showcase>
Showcases featuring this room type.
26 |
# File 'app/models/room_type.rb', line 26 has_many :showcases |
#stores ⇒ ActiveRecord::Relation<Store>
Stores offering this room type.
31 |
# File 'app/models/room_type.rb', line 31 has_and_belongs_to_many :stores |