Class: Condenser::FileWriter
- Inherits:
-
Object
- Object
- Condenser::FileWriter
- Defined in:
- lib/condenser/writers/file_writer.rb
Overview
Writes an asset file to disk
Instance Attribute Summary collapse
-
#mime_types ⇒ Object
readonly
Returns the value of attribute mime_types.
Instance Method Summary collapse
- #call(output_directory, asset) ⇒ Object
- #exist?(asset) ⇒ Boolean
-
#initialize(mime_types: nil) ⇒ FileWriter
constructor
A new instance of FileWriter.
- #path(asset) ⇒ Object
Constructor Details
#initialize(mime_types: nil) ⇒ FileWriter
Returns a new instance of FileWriter.
8 9 10 |
# File 'lib/condenser/writers/file_writer.rb', line 8 def initialize(mime_types: nil) @mime_types = mime_types || '*/*' end |
Instance Attribute Details
#mime_types ⇒ Object (readonly)
Returns the value of attribute mime_types.
6 7 8 |
# File 'lib/condenser/writers/file_writer.rb', line 6 def mime_types @mime_types end |
Instance Method Details
#call(output_directory, asset) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/condenser/writers/file_writer.rb', line 20 def call(output_directory, asset) filename = File.join(output_directory, asset.path) FileUtils.mkdir_p(File.dirname(filename)) Condenser::Utils.atomic_write(filename) do |file| file.write(asset.source) end [asset.filename] end |
#exist?(asset) ⇒ Boolean
16 17 18 |
# File 'lib/condenser/writers/file_writer.rb', line 16 def exist?(asset) ::File.exist?(path(asset)) end |
#path(asset) ⇒ Object
12 13 14 |
# File 'lib/condenser/writers/file_writer.rb', line 12 def path(asset) asset.path end |