Class: IronHammer::Utils::FileSystem
- Inherits:
-
Object
- Object
- IronHammer::Utils::FileSystem
- Defined in:
- lib/iron_hammer/utils/file_system.rb
Class Method Summary collapse
- .copy!(source, destination) ⇒ Object
- .copy_directory!(source, destination) ⇒ Object
- .copy_file!(source, destination) ⇒ Object
- .create_path!(*path) ⇒ Object
- .read_file(*path) ⇒ Object
- .read_lines(*path) ⇒ Object
- .write!(params = {}) ⇒ Object
Class Method Details
.copy!(source, destination) ⇒ Object
15 16 17 |
# File 'lib/iron_hammer/utils/file_system.rb', line 15 def self.copy! source, destination File.directory?(source) ? TheFiler::copy_directory!(source, destination) : FileSystem::copy_file!(source, destination) end |
.copy_directory!(source, destination) ⇒ Object
10 11 12 13 |
# File 'lib/iron_hammer/utils/file_system.rb', line 10 def self.copy_directory! source, destination raise(ArgumentError.new 'source must be a directory') unless File.directory?(source) FileUtils.cp_r source, destination end |
.copy_file!(source, destination) ⇒ Object
4 5 6 7 8 |
# File 'lib/iron_hammer/utils/file_system.rb', line 4 def self.copy_file! source, destination raise(ArgumentError.new 'source must be a file') if File.directory?(source) FileSystem::create_path! File.dirname(destination) FileUtils.cp source, destination end |
.create_path!(*path) ⇒ Object
32 33 34 |
# File 'lib/iron_hammer/utils/file_system.rb', line 32 def self.create_path! *path FileUtils.mkpath(File.join(*path)) unless path.nil? || path.empty? || File.exists?(File.join(*path)) end |
.read_file(*path) ⇒ Object
24 25 26 |
# File 'lib/iron_hammer/utils/file_system.rb', line 24 def self.read_file *path File.open(File.join(*path), 'r') { |file| content = file.read } unless path.nil? || path.empty? end |
.read_lines(*path) ⇒ Object
28 29 30 |
# File 'lib/iron_hammer/utils/file_system.rb', line 28 def self.read_lines *path File.open(File.join(*path), 'r') { |file| file.readlines } unless path.nil? || path.empty? end |
.write!(params = {}) ⇒ Object
19 20 21 22 |
# File 'lib/iron_hammer/utils/file_system.rb', line 19 def self.write! params={} FileSystem::create_path! path = params[:path] File.open(File.join(path, name = params[:name]), 'w') { |file| file.write(content = params[:content]) } end |