Class: CacheMethod::Epoch

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_method/epoch.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Epoch

Returns a new instance of Epoch.



15
16
17
18
19
# File 'lib/cache_method/epoch.rb', line 15

def initialize(options = {})
  options.each do |k, v|
    instance_variable_set "@#{k}", v
  end
end

Instance Attribute Details

#method_idObject (readonly)

Returns the value of attribute method_id.



22
23
24
# File 'lib/cache_method/epoch.rb', line 22

def method_id
  @method_id
end

#objObject (readonly)

Returns the value of attribute obj.



21
22
23
# File 'lib/cache_method/epoch.rb', line 21

def obj
  @obj
end

Class Method Details

.current(options = {}) ⇒ Object



4
5
6
7
# File 'lib/cache_method/epoch.rb', line 4

def current(options = {})
  epoch = new options
  epoch.current
end

.mark_passing(options = {}) ⇒ Object



9
10
11
12
# File 'lib/cache_method/epoch.rb', line 9

def mark_passing(options = {})
  epoch = new options
  epoch.mark_passing
end

Instance Method Details

#cache_keyObject



32
33
34
# File 'lib/cache_method/epoch.rb', line 32

def cache_key
  [ 'CacheMethod', method_signature, obj_hash ].join ','
end

#currentObject



36
37
38
# File 'lib/cache_method/epoch.rb', line 36

def current
  Config.instance.storage.get(cache_key).to_i
end

#mark_passingObject



40
41
42
# File 'lib/cache_method/epoch.rb', line 40

def mark_passing
  Config.instance.storage.set cache_key, (current+1), 0
end

#method_signatureObject



24
25
26
# File 'lib/cache_method/epoch.rb', line 24

def method_signature
  @method_signature ||= ::CacheMethod.method_signature(obj, method_id)
end

#obj_hashObject



28
29
30
# File 'lib/cache_method/epoch.rb', line 28

def obj_hash
  @obj_hash ||= obj.hash
end