module Taeval::FileHelper

Public Instance Methods

create(file, path=nil) click to toggle source
# 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.expand_path(caller_locations.last.path))}/#{file}"
  end
  File.new(full_path, 'w')
end
exist?(file) click to toggle source
# File lib/taeval/file_helper.rb, line 6
def exist?(file)
  return true if File.exist?(file)
  full_path = File.exist?("#{File.dirname(File.expand_path(caller_locations.last.path))}/#{file}")
  File.exist?(full_path)
end
flatten_include!(conf) click to toggle source
# 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) click to toggle source
# File lib/taeval/file_helper.rb, line 36
def open(file, path=nil)
  File.open(file)
end
path_of(file) click to toggle source
# File lib/taeval/file_helper.rb, line 12
def path_of(file)
  return file if File.exist?(file)
  path = "#{File.dirname(File.expand_path(caller_locations.last.path))}/#{file}"
end