Class: SignedForm::Digestor

Inherits:
Object
  • Object
show all
Defined in:
lib/signed_form/digestor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Digestor

Returns a new instance of Digestor



7
8
9
10
11
# File 'lib/signed_form/digestor.rb', line 7

def initialize(template)
  @view_paths = Set.new
  @views  = Set.new
  self << template
end

Instance Attribute Details

#view_pathsObject

Returns the value of attribute view_paths



5
6
7
# File 'lib/signed_form/digestor.rb', line 5

def view_paths
  @view_paths
end

Instance Method Details

#<<(template) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/signed_form/digestor.rb', line 13

def <<(template)
  virtual_path = get_virtual_path(template)
  raise Errors::UnableToDigest, "Unable to get virtual path from template" unless virtual_path

  @views << virtual_path
  @view_paths += template.view_paths.map(&:to_s)
  @digest = nil
rescue NoMethodError
  raise Errors::UnableToDigest, "Unable get view paths from template"
end

#marshal_dumpObject



24
25
26
# File 'lib/signed_form/digestor.rb', line 24

def marshal_dump
  [@views.to_a, to_s]
end

#marshal_load(input) ⇒ Object



28
29
30
31
32
# File 'lib/signed_form/digestor.rb', line 28

def marshal_load(input)
  @views, @digest = input
  @view_paths = []
  @digest.taint
end

#refreshObject



39
40
41
# File 'lib/signed_form/digestor.rb', line 39

def refresh
  @digest = nil
end

#to_sObject Also known as: digest



34
35
36
# File 'lib/signed_form/digestor.rb', line 34

def to_s
  @digest ||= SignedForm.digest_store.fetch(@views.sort.join(':')) { hash_files(glob_files) }
end