Module: Housekeeping::Users

Extended by:
ActiveSupport::Concern
Included in:
GeographicArea, GeographicAreaType, GeographicItem, Language, Namespace, Person, PreparationType, Project, ProjectMember, Repository, Role, Role::SourceRole, Serial, SerialChronology, Source, User
Defined in:
lib/housekeeping/users.rb

Overview

Concern that provides housekeeping and related methods for models that belong_to a creator and updator

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) by

A convenience. When provided creator and updater are set. If creator exists updater is set. Overrides creator/updater if provided second. See tests.

Otu.new(name: 'Aus', by: @user)


55
56
57
# File 'lib/housekeeping/users.rb', line 55

def by
  @by
end

Instance Method Details

- (Object) set_created_by_id (protected)



69
70
71
# File 'lib/housekeeping/users.rb', line 69

def set_created_by_id
  self.created_by_id ||= $user_id
end

- (Object) set_updated_by_id (protected)

TODO: This method _is not_ called in an 'after_save' operation (in User), so this deprecation warning does not apply (?) It may be called in an 'after_save' situation through some other model. It may help to unwind the logic. WRT .changed? vs .saved_changes? Deprecation warning



75
76
77
78
79
80
81
# File 'lib/housekeeping/users.rb', line 75

def set_updated_by_id
  ActiveSupport::Deprecation.silence do
    if (self.changed? || self.new_record?) && !self.updated_by_id_changed? && self.by.blank?
      self.updated_by_id = $user_id
    end
  end
end