Module: Cjoiner::Helpers::Files
- Included in:
- Engines::Engine, Joiner
- Defined in:
- lib/cjoiner/helpers.rb
Instance Method Summary collapse
-
#expand_path(file) ⇒ Object
return Pathname.new.expand_path.
-
#file(file) ⇒ Object
use Pathname.
-
#file_exists(file, halt = true) ⇒ Object
check if a file exists.
-
#load_yaml(file) ⇒ Object
load a yaml file.
-
#move_file(from, to) ⇒ Object
move a file.
-
#read_file(file) ⇒ Object
read file.
-
#temp_file(file, data) ⇒ Object
create a temporal file.
-
#write_file(file, data) ⇒ Object
write data to file.
Instance Method Details
#expand_path(file) ⇒ Object
return Pathname.new.expand_path
48 49 50 |
# File 'lib/cjoiner/helpers.rb', line 48 def (file) Pathname.new(file). end |
#file(file) ⇒ Object
use Pathname
53 54 55 |
# File 'lib/cjoiner/helpers.rb', line 53 def file(file) Pathname.new file end |
#file_exists(file, halt = true) ⇒ Object
check if a file exists
11 12 13 14 15 |
# File 'lib/cjoiner/helpers.rb', line 11 def file_exists(file, halt = true) check = ::File.exists? file raise(Cjoiner::Errors::FileNotFound, file) if !check and halt check end |
#load_yaml(file) ⇒ Object
load a yaml file
18 19 20 21 22 |
# File 'lib/cjoiner/helpers.rb', line 18 def load_yaml(file) if file_exists(file) ::YAML::load_file(file) end end |
#move_file(from, to) ⇒ Object
move a file
25 26 27 28 |
# File 'lib/cjoiner/helpers.rb', line 25 def move_file(from, to) return false if from == to FileUtils.mv from, to end |
#read_file(file) ⇒ Object
read file
31 32 33 |
# File 'lib/cjoiner/helpers.rb', line 31 def read_file(file) File.read(file) if file_exists file end |
#temp_file(file, data) ⇒ Object
create a temporal file
41 42 43 44 45 |
# File 'lib/cjoiner/helpers.rb', line 41 def temp_file(file, data) temp = Tempfile.new(file) << data temp.close temp end |
#write_file(file, data) ⇒ Object
write data to file
36 37 38 |
# File 'lib/cjoiner/helpers.rb', line 36 def write_file(file, data) file.open("w") { |io| io.puts data } end |