Class: Postnhost::Setting
Constant Summary
collapse
- PUBLIC_PAGE_SIZE_RANGE =
Postnhost::Configuration::PUBLIC_PAGE_SIZE_RANGE
- SITE_INDEXING_OPTIONS =
%w[index noindex].freeze
- TIMEZONE_NAMES =
ActiveSupport::TimeZone.all.map { |zone| zone.tzinfo.name }.uniq.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
#schema_default_locale_key, #schema_locale_overrides_hash, #schema_text_for, #schema_translations_for
Class Method Details
.current ⇒ Object
33
34
35
|
# File 'app/models/postnhost/setting.rb', line 33
def self.current
first_or_create!
end
|
.effective_timezone_name ⇒ Object
37
38
39
|
# File 'app/models/postnhost/setting.rb', line 37
def self.effective_timezone_name
current.effective_timezone_name
end
|
Instance Method Details
#canonical_url_for(url) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/models/postnhost/setting.rb', line 61
def canonical_url_for(url)
uri = URI.parse(url)
if effective_site_url.blank?
uri.query = nil
uri.fragment = nil
return uri.to_s
end
path = uri.path.presence || "/"
"#{effective_site_url}#{path}"
end
|
#current_navigation ⇒ Object
85
86
87
|
# File 'app/models/postnhost/setting.rb', line 85
def current_navigation
navigation || create_navigation!
end
|
#effective_public_page_size ⇒ Object
50
51
52
|
# File 'app/models/postnhost/setting.rb', line 50
def effective_public_page_size
public_page_size || Postnhost.config.public_page_size
end
|
#effective_site_url ⇒ Object
46
47
48
|
# File 'app/models/postnhost/setting.rb', line 46
def effective_site_url
site_url.presence || Postnhost.config.site_url
end
|
#effective_timezone_name ⇒ Object
41
42
43
44
|
# File 'app/models/postnhost/setting.rb', line 41
def effective_timezone_name
selected_timezone = timezone.presence || Postnhost.config.default_timezone
ActiveSupport::TimeZone[selected_timezone]&.name || "UTC"
end
|
#schema_setting(key, default: nil) ⇒ Object
81
82
83
|
# File 'app/models/postnhost/setting.rb', line 81
def schema_setting(key, default: nil)
schema_settings_hash[key.to_s].presence || default
end
|
#schema_settings_hash ⇒ Object
77
78
79
|
# File 'app/models/postnhost/setting.rb', line 77
def schema_settings_hash
schema_settings.is_a?(Hash) ? schema_settings.deep_stringify_keys : {}
end
|
#site_configuration_cache_key ⇒ Object
73
74
75
|
# File 'app/models/postnhost/setting.rb', line 73
def site_configuration_cache_key
[effective_site_url, effective_public_page_size, site_indexing]
end
|
#site_url_options ⇒ Object
54
55
56
57
58
59
|
# File 'app/models/postnhost/setting.rb', line 54
def site_url_options
return {} if effective_site_url.blank?
uri = URI.parse(effective_site_url)
{ host: uri.host, protocol: uri.scheme, port: uri.port }
end
|