Class: FileRecord::Record
- Inherits:
-
Object
- Object
- FileRecord::Record
- Defined in:
- lib/file_record/record.rb
Class Method Summary collapse
-
.read_instances(model, file, options = {}) ⇒ Object
Used by read_model and read_log to load all instances from a file.
-
.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_instances(model, file, options = {}) ⇒ Object
Used by read_model and read_log to load all instances from a file
47 48 49 50 51 52 |
# File 'lib/file_record/record.rb', line 47 def read_instances( model, file, ={} ) instances = YAML::load_stream( File.open( file ) ) instances.each do |i| model.new( i ) end end |
.read_log(model, time, options = {}) ⇒ Object
Read in all log model instances from a time stamped file
62 63 64 65 66 67 68 69 70 |
# File 'lib/file_record/record.rb', line 62 def read_log( model, time, ={} ) [:time] = time file_path = FileUtility.new(model, ).file_path if File.exists? file_path read_instances model, file_path end end |
.read_model(model, options = {}) ⇒ Object
Read in all models instances from the model file
55 56 57 58 59 |
# File 'lib/file_record/record.rb', line 55 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 |