Class: Milkshake::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/milkshake/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache) ⇒ Validator

Returns a new instance of Validator.



9
10
11
12
13
14
# File 'lib/milkshake/validator.rb', line 9

def initialize(cache)
  @cache = cache
  
  @link_time = @cache.key('link.time')
  @cache.reset! if relink?
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



7
8
9
# File 'lib/milkshake/validator.rb', line 7

def cache
  @cache
end

Returns the value of attribute link_time.



7
8
9
# File 'lib/milkshake/validator.rb', line 7

def link_time
  @link_time
end

Instance Method Details



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/milkshake/validator.rb', line 16

def current_link_time
  return @current_link_time unless @current_link_time.nil?
  
  path = File.join(RAILS_ROOT, 'tmp', 'relink.txt')
  if File.file?(path)
    @current_link_time = File.mtime(path)
  else
    @current_link_time = Time.now
  end
  
  @current_link_time
end

#persist!Object



33
34
35
# File 'lib/milkshake/validator.rb', line 33

def persist!
  @cache['link.time'] = Time.now
end

#relink?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/milkshake/validator.rb', line 29

def relink?
  (link_time.nil?) or (current_link_time and link_time and current_link_time > link_time)
end