Class: Page

Inherits:
Object
  • Object
show all
Defined in:
lib/soks-view.rb,
lib/soks-model.rb

Overview

Extend the model classes to provide view functions

Direct Known Subclasses

EmptyPage, UploadPage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



44
45
46
# File 'lib/soks-model.rb', line 44

def content
  @content
end

#content_lockObject

Returns the value of attribute content_lock.



44
45
46
# File 'lib/soks-model.rb', line 44

def content_lock
  @content_lock
end

#inserted_intoObject

Returns the value of attribute inserted_into.



45
46
47
# File 'lib/soks-model.rb', line 45

def inserted_into
  @inserted_into
end

Returns the value of attribute links_from.



45
46
47
# File 'lib/soks-model.rb', line 45

def links_from
  @links_from
end

Returns the value of attribute links_lock.



45
46
47
# File 'lib/soks-model.rb', line 45

def links_lock
  @links_lock
end

Returns the value of attribute links_to.



45
46
47
# File 'lib/soks-model.rb', line 45

def links_to
  @links_to
end

#nameObject 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

#revisionsObject

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_onObject



93
# File 'lib/soks-model.rb', line 93

def created_on; @revisions.first.created_on end

#deleted?Boolean

Returns:

  • (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

Returns:

  • (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_indexObject



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, author )
	return nil if new_content == @content
	changes = new_content.changes_from @content
	return nil if changes.empty?
	@revisions << Revision.new( self,  @revisions.length, changes , author )
	@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, author )
	revise( ( number < 0 ) ? $MESSAGES[:page_deleted] : @revisions[ number ].content, author )
end

#scoreObject



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