Module: Challah::UserAttributeable

Extended by:
ActiveSupport::Concern
Included in:
Userable
Defined in:
lib/challah/concerns/user/attributeable.rb

Instance Method Summary collapse

Instance Method Details

#active=(enabled) ⇒ Object

Fallback to pre-enum active column (pre challah 1.4)



24
25
26
27
28
29
30
# File 'lib/challah/concerns/user/attributeable.rb', line 24

def active=(enabled)
  if self.class.columns.map(&:name).include?("status")
    self.status = (!!enabled ? :active : :inactive)
  else
    write_attribute(:active, !!enabled)
  end
end

#active?Boolean Also known as: active

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'lib/challah/concerns/user/attributeable.rb', line 32

def active?
  # enum-based status
  if self.class.columns.map(&:name).include?("status")
    read_attribute(:status).to_s == "active"

  # support for non-enum status column (pre challah 1.4)
  else
    !!read_attribute(:active)
  end
end

#nameObject

First name and last name together



45
46
47
# File 'lib/challah/concerns/user/attributeable.rb', line 45

def name
  "#{ first_name } #{ last_name }".strip
end

#small_nameObject

shortened name, just includes the first name and last initial



50
51
52
# File 'lib/challah/concerns/user/attributeable.rb', line 50

def small_name
  "#{ first_name.to_s.titleize } #{ last_name.to_s.first.upcase }."
end

#valid_session?Boolean

Is this user valid and ready for a user session?

Override this method if you need to check for a particular configuration on each page request.

Returns:

  • (Boolean)


57
58
59
# File 'lib/challah/concerns/user/attributeable.rb', line 57

def valid_session?
  active?
end