Class: AnimalCracker::FileAssetHost
- Inherits:
-
Object
- Object
- AnimalCracker::FileAssetHost
- Defined in:
- lib/animalcracker/asset_host.rb
Overview
Interface for retrieving assets from the filesystem given some root path.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #find(path_to_asset) ⇒ Object
-
#initialize(root_path) ⇒ FileAssetHost
constructor
A new instance of FileAssetHost.
- #store(path_to_asset, contents) ⇒ Object
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
#root ⇒ Object (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
36 |
# File 'lib/animalcracker/asset_host.rb', line 36 def store(path_to_asset, contents) raise(ReadOnly, "Cannot store files with FileAssetHost"); end |