Class: Account
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Account
- Defined in:
- app/models/account.rb
Overview
Defined Under Namespace
Classes: DomainNotFound, LoginRequired
Constant Summary collapse
- CURRENCY_TYPES =
{ 'British Pound (£)'.html_safe => 'GBP', 'Czech Koruna (Kč)'.html_safe => 'CZK', 'Euro (€)'.html_safe => 'EUR', 'Indian Rupee (Rs)' => 'INR', 'Japanese Yen (¥)'.html_safe => 'JPY', 'Swiss Franc (Fr)' => 'CHF', 'US Dollar ($)' => 'USD' }
Instance Attribute Summary collapse
-
#analytics_validation ⇒ Object
Returns the value of attribute analytics_validation.
-
#email_validation ⇒ Object
Returns the value of attribute email_validation.
-
#general_validation ⇒ Object
Returns the value of attribute general_validation.
-
#media_validation ⇒ Object
Returns the value of attribute media_validation.
-
#metadata_validation ⇒ Object
Returns the value of attribute metadata_validation.
-
#url_base ⇒ Object
——————————————————————————.
-
#url_host ⇒ Object
Returns the value of attribute url_host.
-
#url_protocol ⇒ Object
Returns the value of attribute url_protocol.
Class Method Summary collapse
- .current ⇒ Object
-
.current=(account) ⇒ Object
Since we need the current account for the default scope in models, we need this information easily available at the model level.
-
.current_by_prefix(account_prefix) ⇒ Object
Set the current account by looking up the account prefix.
-
.find_account(host) ⇒ Object
Find the account using the specified host (usually from the request url).
Instance Method Summary collapse
-
#create_default_roles ⇒ Object
——————————————————————————.
-
#current_theme ⇒ Object
Get the name of the current theme - which is simply the account prefix ——————————————————————————.
-
#index_path ⇒ Object
take the root path and use the default locale ——————————————————————————.
-
#parent_theme ⇒ Object
Get the name of the parent theme ——————————————————————————.
-
#set_default_values ⇒ Object
Once an account is found, setup the default url_ values.
-
#set_url_parts(protocol, host) ⇒ Object
set the protocol and host for the account’s url.
-
#site_enabled? ⇒ Boolean
——————————————————————————.
-
#site_locales ⇒ Object
Reutrn an array of locales used for the site.
-
#site_maintenance? ⇒ Boolean
——————————————————————————.
-
#smtp_settings ⇒ Object
——————————————————————————.
-
#ssl_enabled? ⇒ Boolean
——————————————————————————.
-
#theme_data(options = {}) ⇒ Object
Return the current theme’s data structure.
-
#theme_option(option_name) ⇒ Object
Get the value of the specific theme option.
-
#theme_path ⇒ Object
get the account’s theme filesystem path ——————————————————————————.
-
#verify_locale(locale) ⇒ Object
check the local is a supported locale.
Instance Attribute Details
#analytics_validation ⇒ Object
Returns the value of attribute analytics_validation.
19 20 21 |
# File 'app/models/account.rb', line 19 def analytics_validation @analytics_validation end |
#email_validation ⇒ Object
Returns the value of attribute email_validation.
19 20 21 |
# File 'app/models/account.rb', line 19 def email_validation @email_validation end |
#general_validation ⇒ Object
Returns the value of attribute general_validation.
19 20 21 |
# File 'app/models/account.rb', line 19 def general_validation @general_validation end |
#media_validation ⇒ Object
Returns the value of attribute media_validation.
19 20 21 |
# File 'app/models/account.rb', line 19 def media_validation @media_validation end |
#metadata_validation ⇒ Object
Returns the value of attribute metadata_validation.
19 20 21 |
# File 'app/models/account.rb', line 19 def @metadata_validation end |
#url_base ⇒ Object
152 153 154 |
# File 'app/models/account.rb', line 152 def url_base @url_base end |
#url_host ⇒ Object
Returns the value of attribute url_host.
20 21 22 |
# File 'app/models/account.rb', line 20 def url_host @url_host end |
#url_protocol ⇒ Object
Returns the value of attribute url_protocol.
20 21 22 |
# File 'app/models/account.rb', line 20 def url_protocol @url_protocol end |
Class Method Details
.current ⇒ Object
126 127 128 |
# File 'app/models/account.rb', line 126 def self.current Thread.current[:account] end |
.current=(account) ⇒ Object
Since we need the current account for the default scope in models, we need this information easily available at the model level. This is thread safe, as opposed to using a simple cattr_accessor. But we must ensure the that thread info is nulled out after every request using an around_filter
122 123 124 |
# File 'app/models/account.rb', line 122 def self.current=(account) Thread.current[:account] = account end |
.current_by_prefix(account_prefix) ⇒ Object
Set the current account by looking up the account prefix. To be used when operating outside a request, such as from the console
133 134 135 |
# File 'app/models/account.rb', line 133 def self.current_by_prefix(account_prefix) Account.current = Account.find_by_account_prefix(account_prefix) end |
.find_account(host) ⇒ Object
Find the account using the specified host (usually from the request url). Check for certain special subdomains before lookup:
dev, www, backoffice, staging, stg-
Supports xip.io format for testing on local network
dev.testapp.net.192.168.1.5.xip.io
is a valid address. See xip.io for more info
108 109 110 111 112 113 114 |
# File 'app/models/account.rb', line 108 def self.find_account(host) host ||= "" separated = host.downcase.split('.') separated = separated[0..-7] if host.end_with?('xip.io') # strip off xip.io and ip address separated = separated.delete_if { |x| x == 'dev' || x == 'www' || x == 'backoffice' || x =~ /stg-/ || x == 'staging' } self.find_by_domain(separated.join('.')) or raise Account::DomainNotFound.new("Invalid domain: #{host}") end |
Instance Method Details
#create_default_roles ⇒ Object
157 158 159 160 |
# File 'app/models/account.rb', line 157 def create_default_roles Role.unscoped.create!(name: 'admin', account_id: self.id) Role.unscoped.create!(name: 'beta', account_id: self.id) end |
#current_theme ⇒ Object
Get the name of the current theme - which is simply the account prefix
232 233 234 |
# File 'app/models/account.rb', line 232 def current_theme account_prefix end |
#index_path ⇒ Object
take the root path and use the default locale
191 192 193 |
# File 'app/models/account.rb', line 191 def index_path "/#{preferred_default_locale}/index" end |
#parent_theme ⇒ Object
Get the name of the parent theme
238 239 240 |
# File 'app/models/account.rb', line 238 def parent_theme ThemesForRails.config.parent_theme(current_theme) end |
#set_default_values ⇒ Object
Once an account is found, setup the default url_ values.
139 140 141 |
# File 'app/models/account.rb', line 139 def set_default_values set_url_parts(self.ssl_enabled? ? 'https://' : 'http://', self.domain) end |
#set_url_parts(protocol, host) ⇒ Object
set the protocol and host for the account’s url. During request processing, this is usually called with the request.protocol and request.host_with_port
146 147 148 149 |
# File 'app/models/account.rb', line 146 def set_url_parts(protocol, host) self.url_protocol = protocol self.url_host = host end |
#site_enabled? ⇒ Boolean
163 164 165 |
# File 'app/models/account.rb', line 163 def site_enabled? preferred_site_enabled? end |
#site_locales ⇒ Object
Reutrn an array of locales used for the site. Split on commas and whitespace
185 186 187 |
# File 'app/models/account.rb', line 185 def site_locales preferred_locales.split(/,\s*/) end |
#site_maintenance? ⇒ Boolean
168 169 170 |
# File 'app/models/account.rb', line 168 def site_maintenance? preferred_site_maintenance? end |
#smtp_settings ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'app/models/account.rb', line 196 def smtp_settings { :address => preferred_smtp_address, :port => preferred_smtp_port, :domain => preferred_smtp_domain, :user_name => preferred_smtp_user_name, :password => preferred_smtp_password } end |
#ssl_enabled? ⇒ Boolean
173 174 175 |
# File 'app/models/account.rb', line 173 def ssl_enabled? preferred_ssl_enabled? end |
#theme_data(options = {}) ⇒ Object
Return the current theme’s data structure. parent: true will give the parent theme’s data if no data exists, return an empty hash
210 211 212 213 214 215 216 |
# File 'app/models/account.rb', line 210 def theme_data( = {}) if [:parent] ThemesForRails.config.themes_data(parent_theme) || {} else ThemesForRails.config.themes_data(current_theme) || {} end end |
#theme_option(option_name) ⇒ Object
Get the value of the specific theme option.
220 221 222 |
# File 'app/models/account.rb', line 220 def theme_option(option_name) theme_data(parent: true).merge(theme_data)[option_name.to_s] end |
#theme_path ⇒ Object
get the account’s theme filesystem path
226 227 228 |
# File 'app/models/account.rb', line 226 def theme_path "#{ThemesForRails.config.themes_path}/#{current_theme}" end |
#verify_locale(locale) ⇒ Object
check the local is a supported locale. If not, return site default
179 180 181 |
# File 'app/models/account.rb', line 179 def verify_locale(locale) (site_locales.include? locale.to_s) ? locale : preferred_default_locale end |