Module: Taeval::FileHelper
- Included in:
- ConfigManager, Executor, GitCheckout::Config, Hadolint::Config, Plagium::Config, Reporter, Unittest::Config
- Defined in:
- lib/taeval/file_helper.rb
Instance Method Summary collapse
- #create(file, path = nil) ⇒ Object
- #exist?(file) ⇒ Boolean
- #flatten_include!(conf) ⇒ Object
- #open(file, path = nil) ⇒ Object
- #path_of(file) ⇒ Object
Instance Method Details
#create(file, path = nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/taeval/file_helper.rb', line 27 def create(file, path=nil) if !path.nil? && File.exist?(path) && File.directory?(path) full_path = "#{path}/#{file}" else full_path = "#{File.dirname(File.(caller_locations.last.path))}/#{file}" end File.new(full_path, 'w') end |
#exist?(file) ⇒ Boolean
6 7 8 9 10 |
# File 'lib/taeval/file_helper.rb', line 6 def exist?(file) return true if File.exist?(file) full_path = File.exist?("#{File.dirname(File.(caller_locations.last.path))}/#{file}") File.exist?(full_path) end |
#flatten_include!(conf) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/taeval/file_helper.rb', line 17 def flatten_include!(conf) conf.each_pair do |k, v| if conf[k].is_a?(Hash) && conf[k].has_key?('include') path = path_of(conf[k]['include']) conf[k] = YAML.load(File.read(path)) conf[k].delete('include') end end end |
#open(file, path = nil) ⇒ Object
36 37 38 |
# File 'lib/taeval/file_helper.rb', line 36 def open(file, path=nil) File.open(file) end |
#path_of(file) ⇒ Object
12 13 14 15 |
# File 'lib/taeval/file_helper.rb', line 12 def path_of(file) return file if File.exist?(file) path = "#{File.dirname(File.(caller_locations.last.path))}/#{file}" end |