Class: FileRecord::Record
- Inherits:
-
Object
- Object
- FileRecord::Record
- Defined in:
- lib/file_record/record.rb
Class Method Summary collapse
-
.read_log(model, time, options = {}) ⇒ Object
Read in all log model instances from a time stamped file.
-
.read_model(model, options = {}) ⇒ Object
Read in all models instances from the model file.
-
.save_log(model, options = {}) ⇒ Object
record a child of Tempo::Model::Log.
-
.save_model(model, options = {}) ⇒ Object
record a child of Tempo::Model::Base.
Class Method Details
.read_log(model, time, options = {}) ⇒ Object
Read in all log model instances from a time stamped file
53 54 55 56 57 58 59 60 61 |
# File 'lib/file_record/record.rb', line 53 def read_log( model, time, ={} ) [:time] = time file_path = FileUtility.new(model, ).file_path if File.exist? file_path read_instances model, file_path end end |
.read_model(model, options = {}) ⇒ Object
Read in all models instances from the model file
46 47 48 49 50 |
# File 'lib/file_record/record.rb', line 46 def read_model( model, ={} ) file_path = FileUtility.new(model, ).file_path read_instances model, file_path end |
.save_log(model, options = {}) ⇒ Object
record a child of Tempo::Model::Log
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/file_record/record.rb', line 27 def save_log( model, ={} ) = .dup [:create] = true [:destroy] = true model.days_index.each do |day, days_logs| [:time] = day ut = FileUtility.new(model, ) # don't create an empty file next if days_logs.empty? ut.save_instances_to_file days_logs end end |
.save_model(model, options = {}) ⇒ Object
record a child of Tempo::Model::Base
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/file_record/record.rb', line 11 def save_model( model, ={} ) = .dup [:create] = true [:destroy] = true file_path = FileUtility.new(model, ).file_path File.open( file_path,'a' ) do |f| model.index.each do |m| f.puts YAML::dump( m.freeze_dry ) end end end |