Class: Cash::Index

Inherits:
Object
  • Object
show all
Includes:
Attributes, Commands
Defined in:
lib/cash/index.rb

Defined Under Namespace

Modules: Attributes, Commands

Constant Summary collapse

DEFAULT_OPTIONS =
{ :ttl => 1.day }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attributes

#buffer, #limit, #order, #order_column, #ttl, #window

Methods included from Commands

#add, #delete, #remove, #update

Constructor Details

#initialize(config, active_record, attributes, options = {}) ⇒ Index

Returns a new instance of Index.



9
10
11
12
# File 'lib/cash/index.rb', line 9

def initialize(config, active_record, attributes, options = {})
  DEFAULT_OPTIONS[:ttl] = config.ttl || DEFAULT_OPTIONS[:ttl]
  @config, @active_record, @attributes, @options = config, active_record, Array(attributes).collect(&:to_s).sort, DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/cash/index.rb', line 3

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/cash/index.rb', line 3

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



14
15
16
17
18
19
20
21
# File 'lib/cash/index.rb', line 14

def ==(other)
  case other
  when Index
    attributes == other.attributes
  else
    attributes == Array(other)
  end
end

#matches?(query) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'lib/cash/index.rb', line 79

def matches?(query)
  query.calculation? ||
  (query.order == [order_column, order] &&
  (!limit || (query.limit && query.limit + query.offset <= limit)))
end

#serialize_object(object) ⇒ Object



75
76
77
# File 'lib/cash/index.rb', line 75

def serialize_object(object)
  primary_key? ? object.shallow_clone : object.id
end