Class: Noumenon::AssetRepository::FileSystem
- Inherits:
-
Noumenon::AssetRepository
- Object
- Noumenon::AssetRepository
- Noumenon::AssetRepository::FileSystem
- Defined in:
- lib/noumenon/asset_repository/file_system.rb
Overview
A content repository which uses YAML files within the filesystem for storage.
Instance Attribute Summary
Attributes inherited from Noumenon::AssetRepository
Instance Method Summary collapse
- #filesystem_path_for(path) ⇒ Object
-
#get(path) ⇒ Object
Retreive a static asset to the repository.
- #get_asset_path(path) ⇒ Object
-
#initialize(options = {}) ⇒ FileSystem
constructor
A new instance of FileSystem.
-
#put(path, content) ⇒ Object
Save a static asset to the repository.
Methods inherited from Noumenon::AssetRepository
Constructor Details
#initialize(options = {}) ⇒ FileSystem
Returns a new instance of FileSystem.
25 26 27 28 29 30 31 |
# File 'lib/noumenon/asset_repository/file_system.rb', line 25 def initialize( = {}) unless .key? :path raise ArgumentError.new("You must provide a path to the asset repository: Noumenon::AssetRepository::FileSystem.new(path: '/tmp')") end super end |
Instance Method Details
#filesystem_path_for(path) ⇒ Object
61 62 63 |
# File 'lib/noumenon/asset_repository/file_system.rb', line 61 def filesystem_path_for(path) File.join [:path], path end |
#get(path) ⇒ Object
Retreive a static asset to the repository.
50 51 52 53 54 |
# File 'lib/noumenon/asset_repository/file_system.rb', line 50 def get(path) return nil unless File.exist?(filesystem_path_for(path)) return nil unless File.extname(path).size > 0 File.read filesystem_path_for(path) end |
#get_asset_path(path) ⇒ Object
56 57 58 59 |
# File 'lib/noumenon/asset_repository/file_system.rb', line 56 def get_asset_path(path) return nil unless File.extname(path).size > 0 filesystem_path_for path end |
#put(path, content) ⇒ Object
Save a static asset to the repository.
37 38 39 40 41 42 43 44 |
# File 'lib/noumenon/asset_repository/file_system.rb', line 37 def put(path, content) raise ArgumentError.new("Assets must have a file extension.") unless File.extname(path).size > 0 full_path = filesystem_path_for(path) directory = File.dirname(full_path) FileUtils.mkdir_p(directory) unless File.exist?(directory) File.open(full_path, "w") { |f| f.write content } end |