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.27 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.26 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.25 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.23 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.22 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.21 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.20 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.19 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.18 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.17 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.16 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.15 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.14 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.13 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.12 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.11 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.10 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.9 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.8 lib/workarea/ext/mongoid/lookup_hash.rb
workarea-core-3.5.7 lib/workarea/ext/mongoid/lookup_hash.rb