Class: Guts::User

Inherits:
ApplicationRecord show all
Includes:
GrantedConcern
Defined in:
app/models/guts/user.rb

Overview

User model

Constant Summary collapse

VALID_EMAIL_REGEX =

Regex to test email against for validation

/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

Instance Method Summary collapse

Instance Method Details

#email=(email) ⇒ String

Setter override for email to downcase and strip email before database

Parameters:

  • email (String)

    the email to set

Returns:

  • (String)

    cleaned email string



32
33
34
# File 'app/models/guts/user.rb', line 32

def email=(email)
  self[:email] = email.downcase.strip
end

#in_group?(lookup) ⇒ Boolean

Quick method for finding if a user is part of a group

Examples:

‘current_user.in_group?(3)` by ID

‘current_user.in_group?(:managers)` by slug

‘current_user.in_group?(’Admins’)‘ by title

Parameters:

  • value (String|Symbol|Fixnum)

    the value to lookup against

Returns:

  • (Boolean)

    user is a part of the group



42
43
44
45
46
47
48
49
50
# File 'app/models/guts/user.rb', line 42

def in_group?(lookup)
  if lookup.is_a?(Symbol)
    groups.map(&:slug).include? lookup.to_s
  elsif lookup.is_a?(String)
    groups.map(&:title).include? lookup
  else
    groups.map(&:id).include? lookup
  end
end