diff options
Diffstat (limited to 'app/models/node.rb')
| -rw-r--r-- | app/models/node.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 5acf563..3564ce4 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -5,16 +5,24 @@ class Node < ActiveRecord::Base | |||
| 5 | 5 | ||
| 6 | # Class methods | 6 | # Class methods |
| 7 | 7 | ||
| 8 | def self.find_page path, revision = :current | 8 | |
| 9 | # Returns a page for a given node. If no revision is supplied, it returns | ||
| 10 | # the last / current one. If a specific revision number is supplied, the | ||
| 11 | # corresponding revision of that page is returned. Get the current / latest | ||
| 12 | # revision with -1. It raises an Argument error if the revision is not a | ||
| 13 | # Fixnum | ||
| 14 | def self.find_page path, revision = -1 | ||
| 15 | unless revision.class == Fixnum | ||
| 16 | raise ArgumentError, "revision must be a Fixnum" | ||
| 17 | end | ||
| 9 | 18 | ||
| 10 | node = Node.find_by_unique_name(path) | 19 | node = Node.find_by_unique_name(path) |
| 11 | 20 | ||
| 12 | if node | 21 | if node |
| 13 | |||
| 14 | case revision | 22 | case revision |
| 15 | when :current | 23 | when -1 |
| 16 | return node.pages.last | 24 | return node.pages.last |
| 17 | when /\d+/ | 25 | else |
| 18 | return node.pages.find_by_revision revision | 26 | return node.pages.find_by_revision revision |
| 19 | end | 27 | end |
| 20 | end | 28 | end |
