Class: Memcacheable::FetchByCriteria

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/memcacheable/fetch_by_criteria.rb

Direct Known Subclasses

FetchBy, FetchWhere

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Fetcher

#debug, #fetch, #flush

Constructor Details

#initialize(klass, *args) ⇒ FetchByCriteria

Returns a new instance of FetchByCriteria.



9
10
11
12
13
14
# File 'lib/memcacheable/fetch_by_criteria.rb', line 9

def initialize(klass, *args)
  self.klass = klass
  self.criteria = args.extract_options!
  raise "Only hash-style args accepted! Illegal args: #{args.inspect}" if args.any?
  raise "No cache_index found in #{klass.name} matching fields #{criteria.keys.inspect}!" unless criteria_cacheable? 
end

Instance Attribute Details

#criteriaObject

Returns the value of attribute criteria.



3
4
5
# File 'lib/memcacheable/fetch_by_criteria.rb', line 3

def criteria
  @criteria
end

#klassObject

Returns the value of attribute klass.



3
4
5
# File 'lib/memcacheable/fetch_by_criteria.rb', line 3

def klass
  @klass
end

Instance Method Details

#criteria_cacheable?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/memcacheable/fetch_by_criteria.rb', line 5

def criteria_cacheable?
  klass.cached_indexes.include? criteria.keys.map(&:to_sym).sort
end