Module: Housekeeping::Users

Extended by:
ActiveSupport::Concern
Included in:
GeographicArea, GeographicAreaType, GeographicItem, Language, Namespace, Organization, 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

#byObject

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

#set_created_by_idObject (protected)



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

def set_created_by_id
  self.created_by_id ||= Current.user_id
end

#set_updated_by_idObject (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



78
79
80
81
82
# File 'lib/housekeeping/users.rb', line 78

def set_updated_by_id
  if (changed? || new_record?) && !updated_by_id_changed? && by.blank?
    self.updated_by_id = Current.user_id
  end
end