Class: Polytrix::StateFile
- Inherits:
-
Object
- Object
- Polytrix::StateFile
- Defined in:
- lib/polytrix/state_file.rb
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(polytrix_root, name) ⇒ StateFile
constructor
A new instance of StateFile.
- #read ⇒ Object
- #write(state) ⇒ Object
Constructor Details
#initialize(polytrix_root, name) ⇒ StateFile
Returns a new instance of StateFile.
6 7 8 9 10 |
# File 'lib/polytrix/state_file.rb', line 6 def initialize(polytrix_root, name) @file_name = File.( File.join(polytrix_root, '.polytrix', "#{name}.yml") ) end |
Instance Method Details
#destroy ⇒ Object
28 29 30 |
# File 'lib/polytrix/state_file.rb', line 28 def destroy FileUtils.rm_f(file_name) if File.exist?(file_name) end |
#read ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/polytrix/state_file.rb', line 12 def read if File.exist?(file_name) Hashie::Mash.load(file_name).dup || {} else Hashie::Mash.new end end |
#write(state) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/polytrix/state_file.rb', line 20 def write(state) dir = File.dirname(file_name) serialized_string = serialize_hash(Util.stringified_hash(state)) FileUtils.mkdir_p(dir) File.open(file_name, 'wb') { |f| f.write(serialized_string) } end |