lib/brief/repository.rb in brief-1.3.1 vs lib/brief/repository.rb in brief-1.3.2

- old
+ new

@@ -45,11 +45,18 @@ 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| - define_method(type.to_s.pluralize) do - Brief::Model.for_type(type).models.to_a + 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 end end