class DataFile

Attributes

root_dir[RW]

Public Class Methods

new(rootdir = nil) click to toggle source
# File lib/rakeutils/filegentask.rb, line 19
def initialize(rootdir = nil)
  @root_dir = rootdir

  if( rootdir )
    @root_dir = File.rubypath(@root_dir)
    if( !File.exists?(@root_dir))
      FileUtils.mkdir(@root_dir)
    end
  end
end

Public Instance Methods

read(filename) click to toggle source
# File lib/rakeutils/filegentask.rb, line 39
def read(filename)
  filepath = filename
  if( root_dir )
    filepath = File.join(root_dir, filename)
  end

  data = {}

  open(filepath) { |f| data = YAML.load(f) }
  data
end
write(filename, data) click to toggle source
# File lib/rakeutils/filegentask.rb, line 30
def write(filename, data)
  filepath = filename
  if( root_dir )
    filepath = File.join(root_dir, filename)
  end

  open(filepath, 'w') { |f| YAML.dump(data, f) }
end