Class: User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- User
- Defined in:
- app/models/user.rb
Overview
Instance Attribute Summary collapse
-
#admin ⇒ Boolean[ true if {User} is a admin otherwise false
Boolean[ true if User is a admin otherwise false.
-
#created_at ⇒ DateTime
Date when User was created.
-
#current_sign_in_at ⇒ DateTime
Date of User current sign in.
-
#current_sign_in_ip ⇒ String
Ip of User current sign in.
-
#forced ⇒ Object
Returns the value of attribute forced.
-
#label ⇒ String
Long User name.
-
#last_sign_in_at ⇒ DateTime
Date of User last sign in.
-
#last_sign_in_ip ⇒ String
Ip of User last sign in.
-
#locked_at ⇒ Datetime
Date when User was blocked.
-
#sign_in_count ⇒ Integer
Counter of User sign in.
-
#updated_at ⇒ DateTime
Date when User was updated.
-
#username ⇒ String
Unique User name.
Instance Method Summary collapse
-
#disable! ⇒ Boolean
update self with #locked_at as Time.zone.now.
-
#enable! ⇒ Boolean
update self with #locked_at as nil.
-
#locked ⇒ Bool
If User with #locked_at present.
- #locked? ⇒ Boolean
Instance Attribute Details
#admin ⇒ Boolean[ true if {User} is a admin otherwise false
Returns Boolean[ true if User is a admin otherwise false.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#created_at ⇒ DateTime
Returns date when User was created.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#current_sign_in_at ⇒ DateTime
Returns date of User current sign in.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#current_sign_in_ip ⇒ String
Returns ip of User current sign in.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#forced ⇒ Object
Returns the value of attribute forced.
43 44 45 |
# File 'app/models/user.rb', line 43 def forced @forced end |
#label ⇒ String
Returns long User name.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#last_sign_in_at ⇒ DateTime
Returns date of User last sign in.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#last_sign_in_ip ⇒ String
Returns ip of User last sign in.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#locked_at ⇒ Datetime
Returns date when User was blocked.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#sign_in_count ⇒ Integer
Returns Counter of User sign in.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#updated_at ⇒ DateTime
Returns date when User was updated.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#username ⇒ String
Returns unique User name.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
Instance Method Details
#disable! ⇒ Boolean
update self with #locked_at as Time.zone.now
62 63 64 |
# File 'app/models/user.rb', line 62 def disable! update(locked_at: Time.zone.now) end |
#enable! ⇒ Boolean
update self with #locked_at as nil
68 69 70 |
# File 'app/models/user.rb', line 68 def enable! update(locked_at: nil) end |
#locked ⇒ Bool
Returns if User with #locked_at present.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/user.rb', line 41 class User < ApplicationRecord store_accessor :metadata, :matr, :responsabile, :data_aggiornamento attr_accessor :forced devise Settings.auth.devise, :trackable, :timeoutable, :lockable default_scope { order(:label) } scope :avaibilities, -> { where(locked_at: nil) } scope :locked, -> { where.not(locked_at: nil) } scope :admins, -> { where(admin: true) } has_many :favorites, class_name: 'UserFaq', inverse_of: :user has_many :faqs, through: :favorites, source: :faq before_validation :presequisite before_destroy :abort_destroy, unless: :forced? validates :username, presence: true, uniqueness: true after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?} # update self with {locked_at} as Time.zone.now # @return [Boolean] true if is updated def disable! update(locked_at: Time.zone.now) end # update self with {locked_at} as nil # @return [Boolean] true if is updated def enable! update(locked_at: nil) end def locked? locked_at? end private def presequisite self.label = username if label.blank? end # is executed before destroy, add an error to :base and abort the action # @return [False] def abort_destroy errors.add :base, 'Can\'t be destroyed' throw :abort end def forced? forced == 'true' end end |
#locked? ⇒ Boolean
72 73 74 |
# File 'app/models/user.rb', line 72 def locked? locked_at? end |