Module: Accounts::BelongsToUser

Defined in:
lib/accounts/belongs_to_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#padma_userObject

Returns the value of attribute padma_user.



11
12
13
# File 'lib/accounts/belongs_to_user.rb', line 11

def padma_user
  @padma_user
end

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/accounts/belongs_to_user.rb', line 7

def self.included(base)
  base.send(:validate, :padma_user_setted_correctly)
end

Instance Method Details

#user(options = {}) ⇒ PadmaUser / PadmaUserDecorator

Returns associated user.

user is stored in instance variable padma_user. This allows for it to be setted in a Mass-Load.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • decorated (TrueClass)
    • returns decorated user

  • force_service_call (TrueClass)
    • forces call to users-ws

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/accounts/belongs_to_user.rb', line 21

def user(options={})
  padma_user ||= Rails.cache.read([username,"padma_user"])

  if padma_user.nil? || options[:force_service_call]
    padma_user = PadmaUser.find(username)
    if padma_user
      Rails.cache.write([username,"padma_user"], padma_user, :expires_in => 5.minutes)
    end
  end

  if options[:decorated] && padma_user
    PadmaUserDecorator.decorate(padma_user)
  else
    padma_user
  end
end