Module: PackRat::CacheHelper::ClassMethods

Defined in:
lib/pack_rat/cache_helper.rb

Instance Method Summary collapse

Instance Method Details

#extended(base) ⇒ Object



12
13
14
15
# File 'lib/pack_rat/cache_helper.rb', line 12

def extended(base)
  base.send(:file_location=, file_location_guesser)
  base.send(:updated_attribute_name=, :updated_at) unless base.updated_attribute_name
end

#file_digestObject



30
31
32
# File 'lib/pack_rat/cache_helper.rb', line 30

def file_digest
  @file_digest
end

#file_digest=(digest) ⇒ Object



33
34
35
# File 'lib/pack_rat/cache_helper.rb', line 33

def file_digest=(digest)
  @file_digest = digest
end

#file_locationObject



23
24
25
# File 'lib/pack_rat/cache_helper.rb', line 23

def file_location
  @file_location
end

#file_location=(path) ⇒ Object



26
27
28
29
# File 'lib/pack_rat/cache_helper.rb', line 26

def file_location=(path)
  @file_location = path
  generate_file_digest
end

#file_location_guesserObject

Uses Rails conventions to determine location of the defined class



50
51
52
# File 'lib/pack_rat/cache_helper.rb', line 50

def file_location_guesser
  "#{Rails.root}/app/models/#{self.to_s.split('::').join('/').underscore.downcase}.rb" if defined? Rails
end

#generate_file_digestObject

Creates MD5 Digest of the set file_location attribute



38
39
40
41
42
43
44
45
46
47
# File 'lib/pack_rat/cache_helper.rb', line 38

def generate_file_digest
  if self.file_location
    begin
      file = File.read(self.file_location)
      self.file_digest = Digest::MD5.hexdigest(file)
    rescue
      self.file_digest = nil
    end
  end
end

#updated_attribute_nameObject



17
18
19
# File 'lib/pack_rat/cache_helper.rb', line 17

def updated_attribute_name
  @updated_attribute_name
end

#updated_attribute_name=(name) ⇒ Object



20
21
22
# File 'lib/pack_rat/cache_helper.rb', line 20

def updated_attribute_name=(name)
  @updated_attribute_name = name
end