Sha256: 09c5efe51a48896a3eb550a2fab499c378948d6fd3896760cc0041db8406049b

Contents?: true

Size: 1.47 KB

Versions: 8

Compression:

Stored size: 1.47 KB

Contents

require 'digest/md5'
require 'dassets/cache'
require 'dassets/source_file'

module Dassets; end
class Dassets::SourceProxy

  attr_reader :digest_path, :content_cache, :fingerprint_cache
  attr_reader :source_files

  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

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

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

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

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

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

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

  private

  def source_content
    @source_files.map{ |f| f.compiled }.join("\n")
  end

  def source_fingerprint
    Digest::MD5.new.hexdigest(source_content)
  end

  def get_source_files(digest_path, options)
    Dassets.config.combinations[digest_path.to_s].map do |source_digest_path|
      Dassets::SourceFile.find_by_digest_path(source_digest_path, options)
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dassets-0.14.5 lib/dassets/source_proxy.rb
dassets-0.14.4 lib/dassets/source_proxy.rb
dassets-0.14.3 lib/dassets/source_proxy.rb
dassets-0.14.2 lib/dassets/source_proxy.rb
dassets-0.14.1 lib/dassets/source_proxy.rb
dassets-0.14.0 lib/dassets/source_proxy.rb
dassets-0.13.2 lib/dassets/source_proxy.rb
dassets-0.13.1 lib/dassets/source_proxy.rb