Class: Stay::Store
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Stay::Store
- Includes:
- TranslatableResource
- Defined in:
- app/models/stay/store.rb
Constant Summary collapse
- TRANSLATABLE_FIELDS =
acts_as_paranoid
%i[meta_description meta_keywords seo_title facebook twitter instagram customer_support_email description address contact_phone new_order_notifications_email].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_deleted? ⇒ Boolean
- #formatted_url ⇒ Object
- #seo_meta_description ⇒ Object
- #supported_currencies_list ⇒ Object
- #supported_locales_list ⇒ Object
- #unique_name ⇒ Object
Class Method Details
.available_locales ⇒ Object
50 51 52 53 54 |
# File 'app/models/stay/store.rb', line 50 def self.available_locales Rails.cache.fetch('stores_available_locales') do Stay::Store.all.map(&:supported_locales_list).flatten.uniq end end |
.default ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/models/stay/store.rb', line 40 def self.default Rails.cache.fetch('default_store') do if where(default: true).any? where(default: true).first else new(default: true) end end end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
80 81 82 |
# File 'app/models/stay/store.rb', line 80 def can_be_deleted? self.class.where.not(id: id).any? end |
#formatted_url ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'app/models/stay/store.rb', line 60 def formatted_url return if url.blank? @formatted_url ||= if url.match(/http:\/\/|https:\/\//) url else Rails.env.development? || Rails.env.test? ? "http://#{url}" : "https://#{url}" end end |
#seo_meta_description ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'app/models/stay/store.rb', line 84 def if .present? elsif seo_title.present? seo_title else name end end |
#supported_currencies_list ⇒ Object
74 75 76 77 78 |
# File 'app/models/stay/store.rb', line 74 def supported_currencies_list @supported_currencies_list ||= (read_attribute(:supported_currencies).to_s.split(',') << default_currency).sort.map(&:to_s).map do |code| ::Money::Currency.find(code.strip) end.uniq.compact end |
#supported_locales_list ⇒ Object
70 71 72 |
# File 'app/models/stay/store.rb', line 70 def supported_locales_list @supported_locales_list ||= (read_attribute(:supported_locales).to_s.split(',') << default_locale).compact.uniq.sort end |
#unique_name ⇒ Object
56 57 58 |
# File 'app/models/stay/store.rb', line 56 def unique_name @unique_name ||= "#{name} (#{code})" end |