Class: Plum::Site
Constant Summary
Plum::StaticCacheInvalidation::CACHE_IRRELEVANT_COLUMNS
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.first_or_create_standalone!(skip_defaults: false) ⇒ Object
29
30
31
|
# File 'app/models/plum/site.rb', line 29
def self.first_or_create_standalone!(skip_defaults: false)
first_or_create!(name: "My Site", theme_name: "default", skip_defaults: skip_defaults)
end
|
.for_owner!(owner, attributes = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/models/plum/site.rb', line 33
def self.for_owner!(owner, attributes = {})
unless owner.respond_to?(:persisted?) && owner.persisted?
raise ArgumentError, "Owner must be a persisted Active Record model"
end
find_or_create_by!(owner: owner) do |site|
site.name = attributes.fetch(:name) { owner_default_name(owner) }
site.theme_name = attributes.fetch(:theme_name, "default")
site.skip_defaults = attributes.fetch(:skip_defaults, false)
site.domain = attributes[:domain] if attributes.key?(:domain)
site.settings = attributes[:settings] if attributes.key?(:settings)
site.theme_settings = attributes[:theme_settings] if attributes.key?(:theme_settings)
site.custom_css = attributes[:custom_css] if attributes.key?(:custom_css)
end
end
|
Instance Method Details
#default_locale ⇒ Object
62
63
64
65
|
# File 'app/models/plum/site.rb', line 62
def default_locale
configured = settings.to_h["default_locale"].to_s
locales.include?(configured) ? configured : locales.first
end
|
#locales ⇒ Object
57
58
59
60
|
# File 'app/models/plum/site.rb', line 57
def locales
configured = Array(settings.to_h["locales"]).map(&:to_s).select { |locale| locale.match?(/\A[a-z]{2}(?:-[A-Z]{2})?\z/) }
configured.presence || [ "en" ]
end
|
#localized? ⇒ Boolean
67
68
69
|
# File 'app/models/plum/site.rb', line 67
def localized?
locales.many?
end
|
#theme_settings ⇒ Object
53
54
55
|
# File 'app/models/plum/site.rb', line 53
def theme_settings
super || {}
end
|