Module: Axis::Document::FinderMethods

Included in:
Base
Defined in:
lib/axis/document.rb

Instance Method Summary collapse

Instance Method Details

#find(id) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/axis/document.rb', line 13

def find(id)
  id = id.to_s
  raise ArgumentError, "id cannot be empty" if id == ""

  Pathname.new(type_path).each_child do |file_path|
    doc = new(file_path)
    return doc if doc.id == id
  end

  raise DocumentNotFound, "with id #{id} in #{type_path}"
end

#find_by_date(year, month = nil, day = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/axis/document.rb', line 25

def find_by_date(year, month = nil, day = nil)
  docs = [] 
  Pathname.new(type_path).each_child do |file_path|
    doc = new(file_path)

    next if doc.created_on.year != year
    next if doc.created_on.month != month if month
    next if doc.created_on.day != day if day

    docs << doc
  end
  docs
end