Sha256: c14eaadb218e5ac50164d7ccd2bf08360727b1089609ae48f4e6f5cefccfb2f2

Contents?: true

Size: 785 Bytes

Versions: 3

Compression:

Stored size: 785 Bytes

Contents

# TODO Delete this file once PR has been accepted
#   https://github.com/mongomapper/mongomapper/pull/641
MongoMapper::Plugins::Keys::Static
module MongoMapper
  module Plugins
    module Keys
      module Static
        module ClassMethods
          def embedded_keys
            @embedded_keys ||= embedded_associations.collect(&:as)
          end

          def embedded_key?(key)
            embedded_keys.include?(key.to_sym)
          end
        end

        private

        def load_from_database(attrs, with_cast = false)
          return super if !self.class.static_keys || !attrs.respond_to?(:each)

          attrs = attrs.select { |key, _| self.class.key?(key) || self.class.embedded_key?(key) }

          super(attrs, with_cast)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rocketjob-2.1.3 lib/rocket_job/extensions/mongo_mapper.rb
rocketjob-2.1.2 lib/rocket_job/extensions/mongo_mapper.rb
rocketjob-2.1.1 lib/rocket_job/extensions/mongo_mapper.rb