Class: Revision
- Inherits:
-
Object
- Object
- Revision
- Defined in:
- lib/soks-model.rb,
lib/soks-upgrade-0.0.2.rb
Overview
This is the definition of Revision from v-0-0-2. Much smaller than the current definition. sigh.
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#created_on ⇒ Object
(also: #revised_on)
readonly
Returns the value of attribute created_on.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#content(page) ⇒ Object
Recreates the content of the page AFTER this revision had been made.
- #following_revision ⇒ Object
-
#initialize(number, changes, author) ⇒ Revision
constructor
A new instance of Revision.
- #method_missing(symbol, *args) ⇒ Object
-
#previous_content(page) ⇒ Object
Recreateds the content of the page BEFORE this revision had been made.
- #previous_revision ⇒ Object
-
#to_a ⇒ Object
To allow the contents to be dumped in a class independent way.
Constructor Details
#initialize(number, changes, author) ⇒ Revision
Returns a new instance of Revision.
9 10 11 |
# File 'lib/soks-model.rb', line 9 def initialize( page, number, changes, , created_on = Time.now ) @page, @number, @changes, @author, @created_on = page, number, changes, , created_on end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
33 34 35 36 |
# File 'lib/soks-model.rb', line 33 def method_missing( symbol, *args ) raise(ArgumentError, "Revision does not respond to #{symbol}", caller) unless @page && @page.respond_to?( symbol ) @page.send symbol, *args end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
5 6 7 |
# File 'lib/soks-model.rb', line 5 def @author end |
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
6 7 8 |
# File 'lib/soks-model.rb', line 6 def changes @changes end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/soks-upgrade-0.0.2.rb', line 7 def created_at @created_at end |
#created_on ⇒ Object (readonly) Also known as: revised_on
Returns the value of attribute created_on.
6 7 8 |
# File 'lib/soks-model.rb', line 6 def created_on @created_on end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
5 6 7 |
# File 'lib/soks-model.rb', line 5 def number @number end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/soks-model.rb', line 5 def page @page end |
Instance Method Details
#content(page) ⇒ Object
Recreates the content of the page AFTER this revision had been made. Done by recursively applying diffs to more recent versions.
15 16 17 |
# File 'lib/soks-model.rb', line 15 def content following_revision ? following_revision.previous_content : page.content end |
#following_revision ⇒ Object
29 30 31 |
# File 'lib/soks-model.rb', line 29 def following_revision page.revision( number + 1 ) end |
#previous_content(page) ⇒ Object
Recreateds the content of the page BEFORE this revision had been made
20 21 22 |
# File 'lib/soks-model.rb', line 20 def previous_content content.split("\n").unpatch!(@changes).join("\n") end |
#previous_revision ⇒ Object
24 25 26 27 |
# File 'lib/soks-model.rb', line 24 def previous_revision return nil if number == 0 page.revision( number - 1 ) end |
#to_a ⇒ Object
To allow the contents to be dumped in a class independent way. Must match the order of the variables used in initialize
40 |
# File 'lib/soks-model.rb', line 40 def to_a() [@number, @changes, @author, @created_on] end |