Class: Page
- Inherits:
-
Object
- Object
- Page
- Defined in:
- lib/soks-view.rb,
lib/soks-model.rb
Overview
Extend the model classes to provide view functions
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_lock ⇒ Object
Returns the value of attribute content_lock.
-
#inserted_into ⇒ Object
Returns the value of attribute inserted_into.
-
#links_from ⇒ Object
Returns the value of attribute links_from.
-
#links_lock ⇒ Object
Returns the value of attribute links_lock.
-
#links_to ⇒ Object
Returns the value of attribute links_to.
-
#name ⇒ Object
(also: #to_s)
Returns the value of attribute name.
-
#revisions ⇒ Object
Returns the value of attribute revisions.
Class Method Summary collapse
-
.empty(name) ⇒ Object
Returns an empty version of itself.
Instance Method Summary collapse
- #<=>(otherpage) ⇒ Object
- #created_on ⇒ Object
- #deleted? ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(name) ⇒ Page
constructor
A new instance of Page.
- #is_inserted_into(page) ⇒ Object
-
#method_missing(symbol, *args) ⇒ Object
Any unhandled calls are passed onto the latest revision (e.g. author, creation time etc).
- #name_for_index ⇒ Object
-
#revise(new_content, author) ⇒ Object
Revises the content of this page, creating a new revision class that stores the changes.
- #revision(number) ⇒ Object
-
#rollback(number, author) ⇒ Object
Returns the content of this page to that of a previous version.
- #score ⇒ Object
- #textile(view = nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Page
Returns a new instance of Page.
58 59 60 61 62 63 |
# File 'lib/soks-model.rb', line 58 def initialize( name ) @content_lock, @links_lock = Mutex.new, Mutex.new @name, @content, @revisions = name, "", [] @links_from, @links_to = [], [] @inserted_into = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
Any unhandled calls are passed onto the latest revision (e.g. author, creation time etc)
104 105 106 107 108 109 110 |
# File 'lib/soks-model.rb', line 104 def method_missing( symbol, *args ) if @revisions.last && @revisions.last.respond_to?(symbol) @revisions.last.send symbol, *args else raise ArgumentError,"Page does not respond to #{symbol}", caller end end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
44 45 46 |
# File 'lib/soks-model.rb', line 44 def content @content end |
#content_lock ⇒ Object
Returns the value of attribute content_lock.
44 45 46 |
# File 'lib/soks-model.rb', line 44 def content_lock @content_lock end |
#inserted_into ⇒ Object
Returns the value of attribute inserted_into.
45 46 47 |
# File 'lib/soks-model.rb', line 45 def inserted_into @inserted_into end |
#links_from ⇒ Object
Returns the value of attribute links_from.
45 46 47 |
# File 'lib/soks-model.rb', line 45 def links_from @links_from end |
#links_lock ⇒ Object
Returns the value of attribute links_lock.
45 46 47 |
# File 'lib/soks-model.rb', line 45 def links_lock @links_lock end |
#links_to ⇒ Object
Returns the value of attribute links_to.
45 46 47 |
# File 'lib/soks-model.rb', line 45 def links_to @links_to end |
#name ⇒ Object Also known as: to_s
Returns the value of attribute name.
44 45 46 |
# File 'lib/soks-model.rb', line 44 def name @name end |
#revisions ⇒ Object
Returns the value of attribute revisions.
44 45 46 |
# File 'lib/soks-model.rb', line 44 def revisions @revisions end |
Class Method Details
.empty(name) ⇒ Object
Returns an empty version of itself.
49 50 51 52 53 54 55 56 |
# File 'lib/soks-model.rb', line 49 def self.empty( name ) empty = self.new( name ) empty.revise( $MESSAGES[:Type_what_you_want_here_and_click_save], "NoOne" ) class << empty def empty?; true; end end empty end |
Instance Method Details
#<=>(otherpage) ⇒ Object
89 |
# File 'lib/soks-model.rb', line 89 def <=>( otherpage ) self.score <=> otherpage.score end |
#created_on ⇒ Object
93 |
# File 'lib/soks-model.rb', line 93 def created_on; @revisions.first.created_on end |
#deleted? ⇒ Boolean
82 83 84 85 |
# File 'lib/soks-model.rb', line 82 def deleted? ( content =~ /^#{$MESSAGES[:page_deleted]}/i ) || ( content =~ /^#{$MESSAGES[:content_moved_to]} /i ) ? true : false end |
#empty? ⇒ Boolean
87 |
# File 'lib/soks-model.rb', line 87 def empty?; @revisions.empty? end |
#is_inserted_into(page) ⇒ Object
95 96 97 |
# File 'lib/soks-model.rb', line 95 def is_inserted_into( page ) @links_lock.synchronize { @inserted_into << page unless @inserted_into.include? page } end |
#name_for_index ⇒ Object
99 |
# File 'lib/soks-model.rb', line 99 def name_for_index; name.downcase end |
#revise(new_content, author) ⇒ Object
Revises the content of this page, creating a new revision class that stores the changes
66 67 68 69 70 71 72 73 |
# File 'lib/soks-model.rb', line 66 def revise( new_content, ) return nil if new_content == @content changes = new_content.changes_from @content return nil if changes.empty? @revisions << Revision.new( self, @revisions.length, changes , ) @content = new_content @revisions.last end |
#revision(number) ⇒ Object
80 |
# File 'lib/soks-model.rb', line 80 def revision( number ) @revisions[ number ] end |
#rollback(number, author) ⇒ Object
Returns the content of this page to that of a previous version
76 77 78 |
# File 'lib/soks-model.rb', line 76 def rollback( number, ) revise( ( number < 0 ) ? $MESSAGES[:page_deleted] : @revisions[ number ].content, ) end |
#score ⇒ Object
91 |
# File 'lib/soks-model.rb', line 91 def score; @links_from.size + @links_to.size end |
#textile(view = nil) ⇒ Object
3 4 5 6 |
# File 'lib/soks-view.rb', line 3 def textile( view = nil ) return "[[#{$MESSAGES[:Create]} #{name} => /edit/#{name} ]]" if empty? content end |