Class: DataFile
- Inherits:
-
Object
- Object
- DataFile
- Defined in:
- lib/rakeutils/filegentask.rb
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
Instance Method Summary collapse
-
#initialize(rootdir = nil) ⇒ DataFile
constructor
A new instance of DataFile.
- #read(filename) ⇒ Object
- #write(filename, data) ⇒ Object
Constructor Details
#initialize(rootdir = nil) ⇒ DataFile
Returns a new instance of DataFile.
19 20 21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#root_dir ⇒ Object
Returns the value of attribute root_dir.
17 18 19 |
# File 'lib/rakeutils/filegentask.rb', line 17 def root_dir @root_dir end |
Instance Method Details
#read(filename) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
30 31 32 33 34 35 36 37 |
# 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 |