Class: PadmaUser
- Inherits:
-
LogicalModel
- Object
- LogicalModel
- PadmaUser
- Includes:
- Gravtastic
- Defined in:
- app/models/padma_user.rb
Constant Summary collapse
- TIMEOUT =
milisecons
5500
- PER_PAGE =
9999
- IGNORED_USERNAMES =
%W(system gympass)
Instance Attribute Summary collapse
-
#cached_current_account ⇒ Object
Returns the value of attribute cached_current_account.
Class Method Summary collapse
Instance Method Summary collapse
- #current_account ⇒ PadmaAccount
-
#enabled_accounts ⇒ Array <PadmaAccount>
Returns me enabled accounts as Padma::Account objects.
-
#json_root ⇒ Object
Attributes will be sent to server under this key.
-
#padma_accounts ⇒ Array <PadmaAccount>
Returns my accounts as Padma::Account objects.
- #verbose_help? ⇒ Boolean
Instance Attribute Details
#cached_current_account ⇒ Object
Returns the value of attribute cached_current_account.
64 65 66 |
# File 'app/models/padma_user.rb', line 64 def cached_current_account @cached_current_account end |
Class Method Details
.find(id, params = {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/padma_user.rb', line 36 def self.find(id, params = {}) if id.in?(IGNORED_USERNAMES) nil else super(id, params) end end |
.find_with_rails_cache(username, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/padma_user.rb', line 44 def self.find_with_rails_cache(username, = {}) pu = Rails.cache.read([username,"padma_user"]) if pu.nil? || [:refresh] pu = find(username) if pu Rails.cache.write([username,"padma_user"], pu, :expires_in => ([:expires_in] || 5.minutes)) end end pu end |
Instance Method Details
#current_account ⇒ PadmaAccount
56 57 58 59 60 61 62 63 |
# File 'app/models/padma_user.rb', line 56 def current_account unless cached_current_account if self.current_account_name self.cached_current_account= PadmaAccount.find_with_rails_cache(self.current_account_name) end end cached_current_account end |
#enabled_accounts ⇒ Array <PadmaAccount>
Returns me enabled accounts as Padma::Account objects
76 77 78 79 |
# File 'app/models/padma_user.rb', line 76 def enabled_accounts return [] if self.accounts.nil? self.accounts.reject{|a|!a['enabled']}.map{|a|PadmaAccount.new(a)} end |
#json_root ⇒ Object
Attributes will be sent to server under this key. json_root => { … attributes }
87 88 89 |
# File 'app/models/padma_user.rb', line 87 def json_root :user end |
#padma_accounts ⇒ Array <PadmaAccount>
Returns my accounts as Padma::Account objects
69 70 71 72 |
# File 'app/models/padma_user.rb', line 69 def padma_accounts return nil if self.accounts.nil? self.accounts.map{|a|PadmaAccount.new(a)} end |
#verbose_help? ⇒ Boolean
81 82 83 |
# File 'app/models/padma_user.rb', line 81 def verbose_help? !!self.verbose_help end |