Module: Resolver::Key::ClassMethods

Defined in:
lib/resolver/key.rb

Instance Method Summary collapse

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 options = @resolver_keys[key.to_sym]
    if options[:unique]
      exists_with?(key, value) ? 1 : 0
    else
      Resolver.redis.scard(index_name(key, value))
    end
  end
end

#exists_with?(key, value) ⇒ Boolean

Returns:

  • (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 options = @resolver_keys[key.to_sym]
    if options[: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, options = {})
  @resolver_keys[name.to_sym] = options || {}
  define_attribute_method(name)
end