diff options
| author | hukl <hukl@eight.local> | 2009-02-08 15:16:22 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.local> | 2009-02-08 15:16:22 +0100 |
| commit | 56306be42c3cb6bfd0501d69e0f3a1842c8f5989 (patch) | |
| tree | 2e3a13c93a78bb90508608b45b75e7ada5801495 /app/models | |
| parent | a6eea1a843c29112a737e77d6cb813c8980fb836 (diff) | |
lots of concept refinements
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/node.rb | 35 | ||||
| -rw-r--r-- | app/models/page.rb | 1 |
2 files changed, 21 insertions, 15 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index cd02657..bc48ac4 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -10,7 +10,6 @@ class Node < ActiveRecord::Base | |||
| 10 | 10 | ||
| 11 | # Class methods | 11 | # Class methods |
| 12 | 12 | ||
| 13 | |||
| 14 | # Returns a page for a given node. If no revision is supplied, it returns | 13 | # Returns a page for a given node. If no revision is supplied, it returns |
| 15 | # the last / current one. If a specific revision number is supplied, the | 14 | # the last / current one. If a specific revision number is supplied, the |
| 16 | # corresponding revision of that page is returned. Get the current / latest | 15 | # corresponding revision of that page is returned. Get the current / latest |
| @@ -37,28 +36,34 @@ class Node < ActiveRecord::Base | |||
| 37 | 36 | ||
| 38 | # Instance Methods | 37 | # Instance Methods |
| 39 | 38 | ||
| 39 | # check if there is a page which has a nil :published_at column | ||
| 40 | # if there is one - it is considered a draft | ||
| 40 | def draft | 41 | def draft |
| 41 | |||
| 42 | # check if there is a page which has a nil :published_at column | ||
| 43 | # if there is one - it is considered a draft else a new revision is | ||
| 44 | # created | ||
| 45 | |||
| 46 | if draft = pages.find_by_published_at(nil) | 42 | if draft = pages.find_by_published_at(nil) |
| 47 | draft | 43 | draft |
| 44 | end | ||
| 45 | end | ||
| 46 | |||
| 47 | def find_or_create_draft user | ||
| 48 | if draft && draft.user == user | ||
| 49 | draft | ||
| 50 | elsif draft && draft.user != user | ||
| 51 | raise "Page is locked" | ||
| 48 | else | 52 | else |
| 49 | # make a new fresh page with node reference | 53 | self.pages.create! :user_id => user.id |
| 50 | draft = Page.create( head.attributes ) | ||
| 51 | end | 54 | end |
| 52 | |||
| 53 | draft | ||
| 54 | end | 55 | end |
| 55 | 56 | ||
| 56 | def publish_draft! | 57 | def publish_draft! |
| 57 | self.head = self.draft | 58 | if self.draft |
| 58 | self.save! | 59 | self.head = self.draft |
| 59 | 60 | self.save! | |
| 60 | self.head.published_at = Time.now | 61 | |
| 61 | self.head.save! | 62 | self.head.published_at = Time.now |
| 63 | self.head.save! | ||
| 64 | else | ||
| 65 | nil | ||
| 66 | end | ||
| 62 | end | 67 | end |
| 63 | 68 | ||
| 64 | # returns an array with all parts of a unique_name rather than a string | 69 | # returns an array with all parts of a unique_name rather than a string |
diff --git a/app/models/page.rb b/app/models/page.rb index df8308b..5647ef9 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -8,6 +8,7 @@ class Page < ActiveRecord::Base | |||
| 8 | 8 | ||
| 9 | # Associations | 9 | # Associations |
| 10 | belongs_to :node | 10 | belongs_to :node |
| 11 | belongs_to :user | ||
| 11 | 12 | ||
| 12 | # Class Methods | 13 | # Class Methods |
| 13 | 14 | ||
