Sha256: 3416f85f2097591a88f968f6929ded243cc2f205a9d535bcf0156d020449b270

Contents?: true

Size: 582 Bytes

Versions: 28

Compression:

Stored size: 582 Bytes

Contents

module Mongoid
  class LookupHash
    delegate_missing_to :@table

    def initialize(klass)
      @klass = klass
      @table = {}
    end

    def [](value)
      @table[value] || @table[@klass.fields['_id'].type.mongoize(value)]
    end
  end

  class Criteria
    def to_lookup_hash
      scoped.each_with_object(LookupHash.new(klass)) do |model, result|
        result[model.id] = model
      end
    end

    alias_method :to_lookup_h, :to_lookup_hash
  end

  module Document
    class_methods do
      delegate :to_lookup_h, :to_lookup_hash, to: :criteria
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.6 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.5 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.4 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.3 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.2 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.1 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.0 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.0.beta.1 lib/workarea/ext/mongoid/lookup_hash.rb