Class | Webby::Resources::DB |
In: |
lib/webby/resources/db.rb
|
Parent: | Object |
A rudimentary "database" for holding resource objects and finding them. The database is held in a Ruby hash keyed by the directories in the content folder.
Add the given resource to the database. It will not be added a second time if it already exists in the database.
Returns an array of resources that are children of the given page resource. A child is any resource that exists in a subdirectory of the page‘s directory.
:sorty_by<Symbol>: | The attribute to sort by |
:reverse<Boolean>: | Reverse the order of the results |
Find a specific resource or collection of resources in the pages database. The first resource found will be returned if the limit is nil. If the limit is an integer, then up to that number of resources will be returned as an array. If the limit is :all, then all resources matching the given attributes will be returned.
Resources can be found using any combination of attributes by passing them in as options to the find method. This will used simple equality comparison to find the resource or resources.
If the :include option is given as :all then all resources that match the finder criteria will be returned in an array. If none are found, an empty array will be returned. If the :include option is given as an integer then the first n resources found will be returned. Otherwise, or if the :include option is not given, the first resource found will be returned
For more complex finders, a block should be supplied. The usage follows that of of the Enumerable#find or Enumerable#find_all methods, depending on the limit. The method will return the first resource or all resources, respectively, for which the block returns true.
:in_directory<String>: | The directory to search. |
:recursive<Boolean>: | Whether or not to recurse into subdirectories |
:sort_by<Symbol>: | Sort results using the given attribute |
:reverse<Boolean>: | Reverse the order of the search results |
# find the "index" resource in the "foo/bar" directory @pages.find( :filename => 'index', :in_directory => 'foo/bar' ) # find all resources under the "foo/bar" directory recursively @pages.find( :all, :in_directory => 'foo/bar', :recursive => true ) # find the resource named "widgets" whose color is "blue" @pages.find( :name => 'widgets', :color => 'blue' ) # find all resources created in the past week @pages.find( :all ) do |resource| resource.created_at > Time.now - (7 * 24 * 3600) end
Returns the parent page of the given resource or nil if the resource is at the root of the directory structure. The parent is the "index" page of the current directory or the next directory up the chain.
Returns an array of resources that are siblings of the given page resource. A sibling is any resource that is in the same directory as the page.
:sorty_by<Symbol>: | The attribute to sort by |
:reverse<Boolean>: | Reverse the order of the results |