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) ⇒ SourceProxy

Returns a new instance of SourceProxy.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dassets/source_proxy.rb', line 13

def initialize(digest_path, **options)
  @digest_path       = digest_path
  @content_cache     = options[:content_cache]     || Dassets::NoCache.new
  @fingerprint_cache = options[:fingerprint_cache] || Dassets::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.



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

def content_cache
  @content_cache
end

#digest_pathObject (readonly)

Returns the value of attribute digest_path.



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

def digest_path
  @digest_path
end

#fingerprint_cacheObject (readonly)

Returns the value of attribute fingerprint_cache.



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

def fingerprint_cache
  @fingerprint_cache
end

#source_filesObject (readonly)

Returns the value of attribute source_files.



11
12
13
# File 'lib/dassets/source_proxy.rb', line 11

def source_files
  @source_files
end

Instance Method Details

#contentObject



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

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

#exists?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/dassets/source_proxy.rb', line 45

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

#fingerprintObject



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

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

#keyObject



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

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

#mtimeObject



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

def mtime
  @source_files.map(&:mtime).compact.max
end

#response_headersObject



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

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