Sha256: eecdae18b02c044c9fd79502bd173a113700b4697d5cf2e1e145111b35d0694a

Contents?: true

Size: 752 Bytes

Versions: 4

Compression:

Stored size: 752 Bytes

Contents

# -*- encoding : utf-8 -*-

module Mongoid
  module Userstamps
    module Updated
      extend ActiveSupport::Concern

      included do
        if !self.included_modules.include?(Mongoid::Userstamps::Model)
          include Mongoid::Userstamps::Model
        end

        belongs_to userstamps_config.updated_name, {
          class_name: userstamps_model.user_model,
          inverse_of: nil,
          optional: true
        }

        set_callback :save, :before, :set_updated_by
      end

      def set_updated_by
        user = self.class.current_user
        return if !user || self.public_send("#{userstamps_config.updated_name}_id_changed?")
        self.public_send("#{userstamps_config.updated_name}=", user)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid-userstamps-3.1.3 lib/mongoid/userstamps/updated.rb
mongoid-userstamps-3.1.2 lib/mongoid/userstamps/updated.rb
mongoid-userstamps-3.1.1 lib/mongoid/userstamps/updated.rb
mongoid-userstamps-3.1.0 lib/mongoid/userstamps/updated.rb