Class: Gin::AssetManifest::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/gin/asset_manifest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, opts = {}) ⇒ Asset

Returns a new instance of Asset.



11
12
13
14
15
16
17
18
# File 'lib/gin/asset_manifest.rb', line 11

def initialize path, opts={}
  @path   = path
  @rtime  = opts[:rtime]  || Time.now
  @mtime  = opts[:mtime]  || File.mtime(path)
  @digest = opts[:digest] || Digest::MD5.file(path).hexdigest
  @target_file = opts[:target_file]
  @dependencies = opts[:dependencies] || []
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



8
9
10
# File 'lib/gin/asset_manifest.rb', line 8

def dependencies
  @dependencies
end

#digestObject (readonly)

Returns the value of attribute digest.



8
9
10
# File 'lib/gin/asset_manifest.rb', line 8

def digest
  @digest
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



8
9
10
# File 'lib/gin/asset_manifest.rb', line 8

def mtime
  @mtime
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/gin/asset_manifest.rb', line 8

def path
  @path
end

#target_fileObject

Returns the value of attribute target_file.



9
10
11
# File 'lib/gin/asset_manifest.rb', line 9

def target_file
  @target_file
end

Instance Method Details

#outdated?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/gin/asset_manifest.rb', line 29

def outdated?
  return true if !File.file?(@path)
  return true if @target_file && !File.file?(@target_file)
  return @mtime != File.mtime(@path) if @rtime - @mtime > 0
  @digest != Digest::MD5.file(@path).hexdigest
end

#to_hashObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gin/asset_manifest.rb', line 37

def to_hash
  hash = {
    :target_file => @target_file,
    :rtime  => @rtime,
    :mtime  => @mtime,
    :digest => @digest }

  hash[:dependencies] = @dependencies.dup unless @dependencies.empty?

  hash
end

#update!Object



21
22
23
24
25
26
# File 'lib/gin/asset_manifest.rb', line 21

def update!
  return unless File.file?(@path)
  @rtime  = Time.now
  @mtime  = File.mtime(@path)
  @digest = Digest::MD5.file(@path).hexdigest
end