Sha256: be8622f76df649c48e63da02181dcf28f4283cf0f65391a48d60584952be90b1

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

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

module Dassets; end
class Dassets::SourceProxy

  attr_reader :digest_path, :source_files, :cache

  def initialize(digest_path, cache = nil)
    @digest_path  = digest_path
    @cache = cache || NoCache.new
    @source_files = get_source_files(@digest_path, @cache)
  end

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

  def content
    @cache["#{self.key} -- content"] ||= source_content
  end

  def fingerprint
    @cache["#{self.key} -- fingerprint"] ||= source_fingerprint
  end

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

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

  private

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

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

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

  class NoCache
    def [](key); end
    def []=(key, value); end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dassets-0.7.0 lib/dassets/source_proxy.rb