Class: Revision

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, author, created_on = Time.now )
	@page, @number, @changes, @author, @created_on = page, number, changes, author, created_on
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object

Raises:

  • (ArgumentError)


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

#authorObject (readonly)

Returns the value of attribute author.



5
6
7
# File 'lib/soks-model.rb', line 5

def author
  @author
end

#changesObject (readonly)

Returns the value of attribute changes.



6
7
8
# File 'lib/soks-model.rb', line 6

def changes
  @changes
end

#created_atObject (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_onObject (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

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/soks-model.rb', line 5

def number
  @number
end

#pageObject (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_revisionObject



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_revisionObject



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_aObject

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