Class: AssetLibrary::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/asset_library/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(absolute_path) ⇒ Asset

Returns a new instance of Asset.



5
6
7
# File 'lib/asset_library/asset.rb', line 5

def initialize(absolute_path)
  @absolute_path = absolute_path
end

Instance Attribute Details

#absolute_pathObject (readonly)

Returns the value of attribute absolute_path.



3
4
5
# File 'lib/asset_library/asset.rb', line 3

def absolute_path
  @absolute_path
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/asset_library/asset.rb', line 9

def eql?(other)
  self.class === other && absolute_path == other.absolute_path
end

#hashObject



13
14
15
# File 'lib/asset_library/asset.rb', line 13

def hash
  self.absolute_path.hash
end

#relative_pathObject



17
18
19
20
21
22
23
# File 'lib/asset_library/asset.rb', line 17

def relative_path
  if AssetLibrary.root == '/'
    absolute_path
  else
    absolute_path[AssetLibrary.root.length..-1]
  end
end

#relative_urlObject



31
32
33
# File 'lib/asset_library/asset.rb', line 31

def relative_url
  "#{relative_path}?#{timestamp.to_i.to_s}"
end

#timestampObject



25
26
27
28
29
# File 'lib/asset_library/asset.rb', line 25

def timestamp
  File.mtime(absolute_path)
rescue Errno::ENOENT
  nil
end