module Hello::RailsActiveRecord::User

Public Instance Methods

as_json_web_api() click to toggle source

CUSTOM METHODS

# File lib/hello/rails_active_record/user.rb, line 69
def as_json_web_api
  as_json
end
email() click to toggle source

GETTERS

# File lib/hello/rails_active_record/user.rb, line 51
def email
  email_credentials.first.email
rescue
  nil
end
email=(v) click to toggle source
# File lib/hello/rails_active_record/user.rb, line 31
def email=(v)
  return if v.blank?
  if email_credentials.any?
    fail "use 'email_credentials.build(email: v)' instead"
  else
    email_credentials.build(user: self, email: v)
  end
end
in_any_role?(roles) click to toggle source
# File lib/hello/rails_active_record/user.rb, line 73
def in_any_role?(roles)
  roles.each { |r| role_is?(r) and return true }
  false
end
password() click to toggle source
# File lib/hello/rails_active_record/user.rb, line 57
def password
  password_credential.password # yes, it might come blank
rescue
  nil
end
password=(v) click to toggle source
# File lib/hello/rails_active_record/user.rb, line 40
def password=(v)
  return if v.blank?
  if password_credentials.any?
    fail "update your 'password_credential' instead"
  else
    password_credential.password=v
  end
end
password_credential() click to toggle source
# File lib/hello/rails_active_record/user.rb, line 63
def password_credential
  @password_credential ||= password_credentials.first_or_initialize(user: self)
end
username=(v) click to toggle source

SETTERS

Calls superclass method
# File lib/hello/rails_active_record/user.rb, line 27
def username=(v)
  super(v.to_s.downcase.remove(' '))
end

Private Instance Methods

hello_validations() click to toggle source
# File lib/hello/rails_active_record/user.rb, line 80
def hello_validations
  c = Hello.configuration
  validates_inclusion_of :locale,    in:   c.locales
  validates_inclusion_of :time_zone, in:   c.time_zones

  hello_validations_username(c)
  hello_validations_email(c)
  hello_validations_password(c)
end
hello_validations_email(c) click to toggle source
# File lib/hello/rails_active_record/user.rb, line 100
def hello_validations_email(c)
  if c.email_presence
    validates_length_of :email_credentials, minimum: 1
    validates_presence_of :email
  end
end
hello_validations_password(c) click to toggle source
# File lib/hello/rails_active_record/user.rb, line 107
def hello_validations_password(c)
  if new_record?
    if c.password_presence
      validates_presence_of :password
    elsif password.blank?
      password_credential.set_generated_password
    end
  end
  validates_length_of :password_credentials, is: 1
end
hello_validations_username(c) click to toggle source
# File lib/hello/rails_active_record/user.rb, line 90
def hello_validations_username(c)
  if c.username_presence
    validates_presence_of :username
  end
  if username.present?
    validates_format_of :username,  with: c.username_regex
    validates_length_of :username,  in:   c.username_length
  end
end