Class: Brief::Repository
- Inherits:
-
Object
- Object
- Brief::Repository
- Includes:
- Enumerable
- Defined in:
- lib/brief/repository.rb
Instance Attribute Summary collapse
-
#briefcase ⇒ Object
readonly
Returns the value of attribute briefcase.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #document_paths ⇒ Object
- #documents ⇒ Object
-
#each(*args, &block) ⇒ Object
should compare vs yield.
-
#initialize(briefcase, options = {}) ⇒ Repository
constructor
A new instance of Repository.
- #load_documents ⇒ Object
- #order_by(*args) ⇒ Object
- #root ⇒ Object
- #where(*args) ⇒ Object
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, = {}) @briefcase = briefcase = load_documents end |
Instance Attribute Details
#briefcase ⇒ Object (readonly)
Returns the value of attribute briefcase.
3 4 5 |
# File 'lib/brief/repository.rb', line 3 def briefcase @briefcase end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/brief/repository.rb', line 3 def end |
Class Method Details
.define_document_finder_methods ⇒ Object
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_paths ⇒ Object
42 43 44 |
# File 'lib/brief/repository.rb', line 42 def document_paths Dir[root.join('**/*.md').to_s].map { |p| Pathname(p) } end |
#documents ⇒ Object
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_documents ⇒ Object
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 |
#root ⇒ Object
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 |