Class: Dassets::SourceProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/dassets/source_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(digest_path, options = nil) ⇒ SourceProxy

Returns a new instance of SourceProxy.



11
12
13
14
15
16
17
18
19
20
# File 'lib/dassets/source_proxy.rb', line 11

def initialize(digest_path, options = nil)
  options ||= {}
  @digest_path       = digest_path
  @content_cache     = options[:content_cache]     || Dassets::Cache::NoCache.new
  @fingerprint_cache = options[:fingerprint_cache] || Dassets::Cache::NoCache.new
  @source_files      = get_source_files(@digest_path, {
    :content_cache     => @content_cache,
    :fingerprint_cache => @fingerprint_cache
  })
end

Instance Attribute Details

#content_cacheObject (readonly)

Returns the value of attribute content_cache.



8
9
10
# File 'lib/dassets/source_proxy.rb', line 8

def content_cache
  @content_cache
end

#digest_pathObject (readonly)

Returns the value of attribute digest_path.



8
9
10
# File 'lib/dassets/source_proxy.rb', line 8

def digest_path
  @digest_path
end

#fingerprint_cacheObject (readonly)

Returns the value of attribute fingerprint_cache.



8
9
10
# File 'lib/dassets/source_proxy.rb', line 8

def fingerprint_cache
  @fingerprint_cache
end

#source_filesObject (readonly)

Returns the value of attribute source_files.



9
10
11
# File 'lib/dassets/source_proxy.rb', line 9

def source_files
  @source_files
end

Instance Method Details

#contentObject



26
27
28
# File 'lib/dassets/source_proxy.rb', line 26

def content
  @content_cache[self.key] ||= source_content
end

#exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dassets/source_proxy.rb', line 42

def exists?
  @source_files.inject(true){ |res, f| res && f.exists? }
end

#fingerprintObject



30
31
32
# File 'lib/dassets/source_proxy.rb', line 30

def fingerprint
  @fingerprint_cache[self.key] ||= source_fingerprint
end

#keyObject



22
23
24
# File 'lib/dassets/source_proxy.rb', line 22

def key
  "#{self.digest_path} -- #{self.mtime}"
end

#mtimeObject



34
35
36
# File 'lib/dassets/source_proxy.rb', line 34

def mtime
  @source_files.map{ |f| f.mtime }.compact.max
end

#response_headersObject



38
39
40
# File 'lib/dassets/source_proxy.rb', line 38

def response_headers
  @source_files.inject(Hash.new){ |hash, f| hash.merge!(f.response_headers) }
end