Class: Cornucopia::Util::FileAsset
- Inherits:
-
Object
- Object
- Cornucopia::Util::FileAsset
- Defined in:
- lib/cornucopia/util/file_asset.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_file(output_location) ⇒ Object
- #body ⇒ Object
- #body=(asset_body) ⇒ Object
- #create_file(output_location) ⇒ Object
-
#initialize(asset_name) ⇒ FileAsset
constructor
A new instance of FileAsset.
- #path ⇒ Object
- #source_file=(source_file_name) ⇒ Object
Constructor Details
#initialize(asset_name) ⇒ FileAsset
Returns a new instance of FileAsset.
23 24 25 26 |
# File 'lib/cornucopia/util/file_asset.rb', line 23 def initialize(asset_name) @asset_name = asset_name @asset_body = nil end |
Class Method Details
.asset(asset_name) ⇒ Object
17 18 19 20 |
# File 'lib/cornucopia/util/file_asset.rb', line 17 def asset(asset_name) Cornucopia::Util::FileAssetCache.instance.asset_cache[asset_name.to_sym] ||= FileAsset.new(asset_name) Cornucopia::Util::FileAssetCache.instance.asset_cache[asset_name.to_sym] end |
Instance Method Details
#add_file(output_location) ⇒ Object
45 46 47 48 49 |
# File 'lib/cornucopia/util/file_asset.rb', line 45 def add_file(output_location) unless (File.exists?(output_location)) create_file(output_location) end end |
#body ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cornucopia/util/file_asset.rb', line 32 def body unless @asset_body self.source_file = path end @asset_body end |
#body=(asset_body) ⇒ Object
28 29 30 |
# File 'lib/cornucopia/util/file_asset.rb', line 28 def body=(asset_body) @asset_body = asset_body end |
#create_file(output_location) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/cornucopia/util/file_asset.rb', line 51 def create_file(output_location) if @asset_body File.open(output_location, "w+") do |write_file| write_file << @asset_body end else FileUtils.cp path, output_location end end |
#path ⇒ Object
61 62 63 |
# File 'lib/cornucopia/util/file_asset.rb', line 61 def path File.absolute_path(File.join(File.dirname(__FILE__), "../source_files/", @asset_name)) end |
#source_file=(source_file_name) ⇒ Object
40 41 42 43 |
# File 'lib/cornucopia/util/file_asset.rb', line 40 def source_file=(source_file_name) # We read the file into memory in case the file moves or is temporary. @asset_body = File.read(source_file_name) end |