Module: PlainRecord::Model::Entry

Defined in:
lib/plain_record/model/entry.rb

Overview

Methods code, that is specific for entry storage, when each file contain only one entry.

Instance Method Summary collapse

Instance Method Details

#delete_entry(file, entry = nil) ⇒ Object



41
42
43
# File 'lib/plain_record/model/entry.rb', line 41

def delete_entry(file, entry = nil)
  delete_file(file)
end

#each_entry(matcher = { }) ⇒ Object



35
36
37
38
39
# File 'lib/plain_record/model/entry.rb', line 35

def each_entry(matcher = { })
  files(matcher).each do |file|
    yield load_file(file)
  end
end

#load_file(file) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/plain_record/model/entry.rb', line 26

def load_file(file)
  unless @loaded.has_key? file
    data, *texts = IO.read(file).split(/\n---[\t ]*\n/, @texts.length + 1)
    data = ::YAML.load(data)
    @loaded[file] = self.new(file, data, texts)
  end
  @loaded[file]
end

#move_entry(entry, from, to) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/plain_record/model/entry.rb', line 45

def move_entry(entry, from, to)
  if from
    @loaded.delete(from)
    delete_file(from)
  end
  @loaded[to] = entry
end