Sha256: ede0276569511964820f89df60bc42a9063f4b3af245c8f9cc2759e6edd05404

Contents?: true

Size: 697 Bytes

Versions: 4

Compression:

Stored size: 697 Bytes

Contents

module Mongoid
  module Userstamps
    module Created
      extend ActiveSupport::Concern

      included do
        unless included_modules.include?(Mongoid::Userstamps::Model)
          include Mongoid::Userstamps::Model
        end

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

        set_callback :create, :before, :set_created_by
      end

      def set_created_by
        user = self.class.current_user
        return if !user || public_send(userstamps_config.created_name)
        public_send("#{userstamps_config.created_name}=", user)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid-userstamps-3.4.1 lib/mongoid/userstamps/created.rb
mongoid-userstamps-3.4.0 lib/mongoid/userstamps/created.rb
mongoid-userstamps-3.3.0 lib/mongoid/userstamps/created.rb
mongoid-userstamps-3.2.1 lib/mongoid/userstamps/created.rb