Module: Hello::RailsActiveRecord::User
- Extended by:
- ActiveSupport::Concern
- Included in:
- User
- Defined in:
- lib/hello/rails_active_record/user.rb
Instance Method Summary collapse
-
#as_json_web_api ⇒ Object
CUSTOM METHODS.
-
#email ⇒ Object
GETTERS.
- #email=(v) ⇒ Object
- #in_any_role?(roles) ⇒ Boolean
- #password ⇒ Object
- #password=(v) ⇒ Object
- #password_credential ⇒ Object
-
#username=(v) ⇒ Object
SETTERS.
Instance Method Details
#as_json_web_api ⇒ Object
CUSTOM METHODS
69 70 71 |
# File 'lib/hello/rails_active_record/user.rb', line 69 def as_json_web_api as_json end |
#email ⇒ Object
GETTERS
51 52 53 54 55 |
# File 'lib/hello/rails_active_record/user.rb', line 51 def email email_credentials.first.email rescue nil end |
#email=(v) ⇒ Object
31 32 33 34 35 36 37 38 |
# 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) ⇒ Boolean
73 74 75 76 |
# 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 ⇒ Object
57 58 59 60 61 |
# 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) ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
63 64 65 |
# 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) ⇒ Object
SETTERS
27 28 29 |
# File 'lib/hello/rails_active_record/user.rb', line 27 def username=(v) super(v.to_s.downcase.remove(' ')) end |