Module: Resolver::Key::ClassMethods
- Defined in:
- lib/resolver/key.rb
Instance Method Summary collapse
- #count_with(key, value) ⇒ Object
- #exists_with?(key, value) ⇒ Boolean
- #find_by(key, value) ⇒ Object
- #key(name, options = {}) ⇒ Object
Instance Method Details
#count_with(key, value) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/resolver/key.rb', line 33 def count_with(key, value) if = @resolver_keys[key.to_sym] if [:unique] exists_with?(key, value) ? 1 : 0 else Resolver.redis.scard(index_name(key, value)) end end end |
#exists_with?(key, value) ⇒ Boolean
29 30 31 |
# File 'lib/resolver/key.rb', line 29 def exists_with?(key, value) Resolver.redis.exists(index_name(key, value)) end |
#find_by(key, value) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/resolver/key.rb', line 19 def find_by(key, value) if = @resolver_keys[key.to_sym] if [:unique] self.find(*Resolver.redis.get(index_name(key, value))) else self.find(Resolver.redis.smembers(index_name(key, value))) end end end |
#key(name, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/resolver/key.rb', line 14 def key(name, = {}) @resolver_keys[name.to_sym] = || {} define_attribute_method(name) end |