Module: DataMapper::Is::Indexed::ClassMethods
- Defined in:
- lib/dm-is-indexed/is/indexed.rb
Instance Method Summary collapse
-
#[](*keys) ⇒ DataMapper::Collection, ...
Allows querying the indexed properties of a Model.
Instance Method Details
#[](*keys) ⇒ DataMapper::Collection, ...
Allows querying the indexed properties of a Model.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dm-is-indexed/is/indexed.rb', line 22 def [](*keys) if keys.length > 1 super(*keys) else key = keys[0] case key when Integer, Range super(*keys) else resource = nil properties.each do |field| if (field.index || field.unique?) if field.valid?(key) resource = first(field => key) break if resource end end end return resource end end end |