Module: Accounts::IsAUser

Defined in:
lib/accounts/is_a_user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/accounts/is_a_user.rb', line 10

def self.included(base)
  base.send(:validate, :has_access_to_current_account)
  base.send(:include, Accounts::BelongsToUser)
  base.send(:include, Accounts::BelongsToAccount)

  base.send(:include, Gravtastic)
  base.send(:gravtastic)

  begin
    unless base.new.respond_to?(:email)
      base.send(:delegate, :email, to: :padma_user, allow_nil: true)
    end
  rescue
    # this is run when booting app, is base model needs DB persistance and this has not yet been provided
    # app will never boot or be able to run migrations. so we rescue exception here.
  end
  base.send(:delegate, :verbose_help?, to: :padma_user, allow_nil: true)
end

Instance Method Details

#csv_options(override_options = {}) ⇒ Hash

Returns CSV options associated with this user from PADMA ACCOUNTS

Returns:

  • (Hash)


59
60
61
62
63
64
65
# File 'lib/accounts/is_a_user.rb', line 59

def csv_options(override_options={})
  options = CSV_DEFAULTS.clone
  options[:col_sep] = self.padma.try :separator
  options[:encoding] = self.padma.try :encoding

  return options.merge(override_options.to_hash.symbolize_keys!)
end

#enabled_accountsArray <PadmaAccount>

Returns enabled accounts associated with this user from PADMA ACCOUNTS

Returns:



52
53
54
# File 'lib/accounts/is_a_user.rb', line 52

def enabled_accounts
  self.padma.try(:enabled_accounts)
end

#encodingObject



67
68
69
# File 'lib/accounts/is_a_user.rb', line 67

def encoding
  @encoding ||= self.padma.encoding 
end

#localeString

Returns locale for this user retrieving it from PADMA ACCOUNTS

Returns:

  • (String)

    locale



45
46
47
# File 'lib/accounts/is_a_user.rb', line 45

def locale
  self.padma.try :locale
end

#padma(cache = true) ⇒ PadmaUser

Parameters:

  • cache (Boolean) (defaults to: true)

Returns:



31
32
33
# File 'lib/accounts/is_a_user.rb', line 31

def padma(cache=true)
  self.user(force_service_call: !cache)
end

#padma_enabled?TrueClass

Returns true if this user has enabled padma accounts

Returns:

  • (TrueClass)


38
39
40
41
# File 'lib/accounts/is_a_user.rb', line 38

def padma_enabled?
  ea = self.enabled_accounts
  !(ea.nil? || ea.empty?)
end

#separatorObject



71
72
73
# File 'lib/accounts/is_a_user.rb', line 71

def separator
  @separator ||= self.padma.separator
end