Class: Brief::Repository

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/brief/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(briefcase, options = {}) ⇒ Repository

Returns a new instance of Repository.



12
13
14
15
16
17
# File 'lib/brief/repository.rb', line 12

def initialize(briefcase, options = {})
  @briefcase = briefcase
  @options = options

  load_documents
end

Instance Attribute Details

#briefcaseObject (readonly)

Returns the value of attribute briefcase.



3
4
5
# File 'lib/brief/repository.rb', line 3

def briefcase
  @briefcase
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/brief/repository.rb', line 3

def options
  @options
end

Class Method Details

.define_document_finder_methodsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/brief/repository.rb', line 46

def self.define_document_finder_methods
  # Create a finder method on the repository
  # which lets us find instances of models by their class name
  Brief::Model.table.keys.each do |type|
    plural = type.to_s.pluralize

    define_method("#{ plural }") do
      instance_variable_get("@#{ plural }") || send("#{ plural }!")
    end

    define_method("#{ plural }!") do
      instance_variable_set("@#{plural}", Brief::Model.for_type(type).models.to_a)
      instance_variable_get("@#{ plural }")
    end
  end
end

Instance Method Details

#document_pathsObject



42
43
44
# File 'lib/brief/repository.rb', line 42

def document_paths
  Dir[root.join('**/*.md').to_s].map { |p| Pathname(p) }
end

#documentsObject



19
20
21
22
# File 'lib/brief/repository.rb', line 19

def documents
  return @documents if @documents
  load_documents
end

#each(*args, &block) ⇒ Object

should compare vs yield



8
9
10
# File 'lib/brief/repository.rb', line 8

def each(*args, &block)
  documents.send(:each, *args, &block)
end

#load_documentsObject



36
37
38
39
40
# File 'lib/brief/repository.rb', line 36

def load_documents
  @documents = document_paths.map do |path|
    Brief::Document.new(path)
  end
end

#order_by(*args) ⇒ Object



28
29
30
# File 'lib/brief/repository.rb', line 28

def order_by(*args)
  Brief::DocumentMapper::Query.new(self).send(:order_by, *args)
end

#rootObject



32
33
34
# File 'lib/brief/repository.rb', line 32

def root
  briefcase.root
end

#where(*args) ⇒ Object



24
25
26
# File 'lib/brief/repository.rb', line 24

def where(*args)
  Brief::DocumentMapper::Query.new(self).send(:where, *args)
end