Class: FolderTemplate::FsAdapter
- Inherits:
-
Object
- Object
- FolderTemplate::FsAdapter
- Defined in:
- lib/folder_template/fs_adapter.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #append_to_file(filename, content) ⇒ Object
-
#initialize(base_path, **opts) ⇒ FsAdapter
constructor
A new instance of FsAdapter.
- #makedirs(dirname) ⇒ Object
- #write_to_file(filename, content) ⇒ Object
Constructor Details
#initialize(base_path, **opts) ⇒ FsAdapter
Returns a new instance of FsAdapter.
16 17 18 19 |
# File 'lib/folder_template/fs_adapter.rb', line 16 def initialize( base_path, **opts ) @base_path = base_path @opts = opts end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
13 14 15 |
# File 'lib/folder_template/fs_adapter.rb', line 13 def base_path @base_path end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
14 15 16 |
# File 'lib/folder_template/fs_adapter.rb', line 14 def opts @opts end |
Instance Method Details
#append_to_file(filename, content) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/folder_template/fs_adapter.rb', line 41 def append_to_file( filename, content ) target = File.join( base_path, filename ) puts "Appending content to file #{filename} ..." if opts[:verbose] FileUtils.makedirs( File.dirname( target ) ) File.open( target, "a" ) { |f| f.write( content ) } end |
#makedirs(dirname) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/folder_template/fs_adapter.rb', line 21 def makedirs( dirname ) target = File.join( base_path, dirname ) return if ( File.directory?( target ) ) puts "Creating diectory #{dirname} ..." if opts[:verbose] FileUtils.makedirs( target ) end |
#write_to_file(filename, content) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/folder_template/fs_adapter.rb', line 29 def write_to_file( filename, content ) target = File.join( base_path, filename ) if ( File.exist?( target ) && ! opts[:overwrite_files] ) puts "Skiping file #{filename} ..." if opts[:verbose] else puts "Generating file #{filename} ..." if opts[:verbose] FileUtils.makedirs( File.dirname( target ) ) File.write( target, content ) end end |