Module: Gluey::AssetRetrieving

Included in:
Warehouse
Defined in:
lib/gluey/warehouse/asset_retrieving.rb

Constant Summary collapse

MARK_PARSER =
%r_^[^\.]+\.(?:([a-f0-9]{32})\.)?\w+$_

Instance Method Summary collapse

Instance Method Details

#assets_pathObject



26
27
28
# File 'lib/gluey/warehouse/asset_retrieving.rb', line 26

def assets_path
  @assets_path ||= "#{root}/public#{path_prefix}"
end

#fetch(asset_type, path, mark = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/gluey/warehouse/asset_retrieving.rb', line 15

def fetch(asset_type, path, mark=nil)
  extant_path = real_path asset_type, path
  return unless mark == extant_path.match(MARK_PARSER)[1]

  file = "#{assets_path}/#{asset_type}/#{extant_path}"
  file if File.exists? file

rescue ::Gluey::ListingError
  nil
end

#real_path(asset_type, path) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/gluey/warehouse/asset_retrieving.rb', line 5

def real_path(asset_type, path)
  list = @listing[asset_type]
  raise ::Gluey::ListingError.new("Asset type #{asset_type} is not defined!") unless list

  real_path = list[path]
  raise ::Gluey::ListingError.new("Unknown asset: #{path}, type=#{asset_type}!") unless real_path

  real_path
end