class FileRecord::Record

Public Class Methods

read_log( model, time, options={} ) click to toggle source

Read in all log model instances from a time stamped file

# File lib/file_record/record.rb, line 53
def read_log( model, time, options={} )

  options[:time] = time
  file_path = FileUtility.new(model, options).file_path

  if File.exists? file_path
    read_instances model, file_path
  end
end
read_model( model, options={} ) click to toggle source

Read in all models instances from the model file

# File lib/file_record/record.rb, line 46
def read_model( model, options={} )

  file_path = FileUtility.new(model, options).file_path
  read_instances model, file_path
end
save_log( model, options={} ) click to toggle source

record a child of Tempo::Model::Log

# File lib/file_record/record.rb, line 27
def save_log( model, options={} )

  options = options.dup
  options[:create] = true
  options[:destroy] = true

  model.days_index.each do |day, days_logs|

    options[:time] = day
    ut = FileUtility.new(model, options)

    # don't create an empty file
    next if days_logs.empty?

    ut.save_instances_to_file days_logs
  end
end
save_model( model, options={} ) click to toggle source

record a child of Tempo::Model::Base

# File lib/file_record/record.rb, line 11
def save_model( model, options={} )

  options = options.dup
  options[:create] = true
  options[:destroy] = true

  file_path = FileUtility.new(model, options).file_path

  File.open( file_path,'a' ) do |f|
    model.index.each do |m|
      f.puts YAML::dump( m.freeze_dry )
    end
  end
end

Protected Class Methods

read_instances( model, file, options={} ) click to toggle source

Used by read_model and read_log to load all instances from a file

# File lib/file_record/record.rb, line 66
def read_instances( model, file, options={} )
  instances = YAML::load_stream( File.open( file ) )
  instances.each do |i|
    model.new( i )
  end
end