Class: Locomotive::Mounter::Writer::FileSystem::Base
- Inherits:
-
Object
- Object
- Locomotive::Mounter::Writer::FileSystem::Base
- Includes:
- Utils::Output
- Defined in:
- lib/locomotive/mounter/writer/file_system/base.rb
Direct Known Subclasses
ContentAssetsWriter, ContentEntriesWriter, ContentTypesWriter, PagesWriter, SiteWriter, SnippetsWriter, ThemeAssetsWriter, TranslationsWriter
Instance Attribute Summary collapse
-
#mounting_point ⇒ Object
Returns the value of attribute mounting_point.
-
#runner ⇒ Object
Returns the value of attribute runner.
Instance Method Summary collapse
-
#create_folder(path) ⇒ Object
Helper method to create a folder from a relative path.
-
#initialize(mounting_point, runner) ⇒ Base
constructor
A new instance of Base.
-
#open_file(path, mode = 'w', &block) ⇒ Object
Open a file described by the relative path.
-
#prepare ⇒ Object
It should always be called before executing the write method.
- #target_path ⇒ Object
-
#write ⇒ Object
Writers inheriting from this class must overide it.
Constructor Details
#initialize(mounting_point, runner) ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 12 def initialize(mounting_point, runner) self.mounting_point = mounting_point self.runner = runner end |
Instance Attribute Details
#mounting_point ⇒ Object
Returns the value of attribute mounting_point.
10 11 12 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 10 def mounting_point @mounting_point end |
#runner ⇒ Object
Returns the value of attribute runner.
10 11 12 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 10 def runner @runner end |
Instance Method Details
#create_folder(path) ⇒ Object
Helper method to create a folder from a relative path
33 34 35 36 37 38 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 33 def create_folder(path) fullpath = File.join(self.target_path, path) unless File.exists?(fullpath) FileUtils.mkdir_p(fullpath) end end |
#open_file(path, mode = 'w', &block) ⇒ Object
Open a file described by the relative path. The file will be closed after the execution of the block.
46 47 48 49 50 51 52 53 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 46 def open_file(path, mode = 'w', &block) # make sure the target folder exists self.create_folder(File.dirname(path)) fullpath = File.join(self.target_path, path) File.open(fullpath, mode, &block) end |
#prepare ⇒ Object
It should always be called before executing the write method. Writers inheriting from this class can overide it
20 21 22 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 20 def prepare self.output_title(:writing) end |
#target_path ⇒ Object
55 56 57 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 55 def target_path self.runner.target_path end |
#write ⇒ Object
Writers inheriting from this class must overide it
25 26 27 |
# File 'lib/locomotive/mounter/writer/file_system/base.rb', line 25 def write raise 'The write method has to be overridden' end |