Class: AnimalCracker::FileAssetHost

Inherits:
Object
  • Object
show all
Defined in:
lib/animalcracker/asset_host.rb

Overview

Interface for retrieving assets from the filesystem given some root path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ FileAssetHost

Returns a new instance of FileAssetHost.



26
27
28
# File 'lib/animalcracker/asset_host.rb', line 26

def initialize(root_path)
  @root = Pathname.new(root_path).realpath
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



25
26
27
# File 'lib/animalcracker/asset_host.rb', line 25

def root
  @root
end

Instance Method Details

#find(path_to_asset) ⇒ Object



30
31
32
33
34
# File 'lib/animalcracker/asset_host.rb', line 30

def find(path_to_asset)
  (@root + path_to_asset.gsub(/^\//, '')).read
rescue Errno::ENOENT
  raise(NotFound, "Could not find #{path_to_asset}")
end

#store(path_to_asset, contents) ⇒ Object

Raises:



36
# File 'lib/animalcracker/asset_host.rb', line 36

def store(path_to_asset, contents) raise(ReadOnly, "Cannot store files with FileAssetHost"); end