Class: FileRecord::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/file_record/record.rb

Class Method Summary collapse

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, options={} )

  options[:time] = time
  file_path = FileUtility.new(model, options).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, options={} )

  file_path = FileUtility.new(model, options).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, 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 = {}) ⇒ 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, 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