Module: Friendly::Document::Convenience::ClassMethods
- Defined in:
- lib/friendly/document/convenience.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#collection_klass ⇒ Object
11 12 13 |
# File 'lib/friendly/document/convenience.rb', line 11 def collection_klass @collection_klass ||= WillPaginate::Collection end |
Instance Method Details
#create(attributes = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/friendly/document/convenience.rb', line 28 def create(attributes = {}) doc = new(attributes) doc.save doc end |
#find(id) ⇒ Object
15 16 17 18 19 |
# File 'lib/friendly/document/convenience.rb', line 15 def find(id) doc = first(:id => id) raise RecordNotFound, "Couldn't find #{name}/#{id}" if doc.nil? doc end |
#paginate(conditions) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/friendly/document/convenience.rb', line 21 def paginate(conditions) query = query(conditions) count = count(query) collection = collection_klass.new(query.page, query.per_page, count) collection.replace(all(query)) end |