Class: Wiki
Overview
This class has turned into a behmoth, need to refactor.
Constant Summary
collapse
- PAGE_CLASSES =
[
[ /^picture of/i, ImagePage ],
[ /^attached/i, AttachmentPage ],
[ /.*/, Page ]
]
- CACHE_NAME =
'pages'
WikiCacheStore::CACHE_EXTENSION
WikiFlatFileStore::CONTENT_EXTENSION, WikiFlatFileStore::DEFAULT_AUTHOR, WikiFlatFileStore::REVISIONS_EXTENSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
#cache_filename_for, #load_cache, #save_cache
#check_disk_for_updated_page, #content_newer_than_revisions?, #delete_files_for_page, #filename_for_content, #filename_for_revisions, #load_all_pages, #load_content, #load_page, #load_revisions, #move_files_for_page, #move_files_if_names_are_not_url_encoded, #page_name_for, #reconstruct_content_from_revisions, #save, #save_all_revisions, #save_content, #save_last_revision
Constructor Details
#initialize(content_folder, cache_folder = nil) ⇒ Wiki
Returns a new instance of Wiki.
146
147
148
149
150
151
152
153
|
# File 'lib/soks-model.rb', line 146
def initialize( content_folder, cache_folder = nil )
@cache_folder = cache_folder
@folder = content_folder
@pages = load_cache(CACHE_NAME) || {}
@shutting_down = false
@check_files_every = nil
watch_for(:start) { start }
end
|
Instance Attribute Details
#check_files_every ⇒ Object
Returns the value of attribute check_files_every.
136
137
138
|
# File 'lib/soks-model.rb', line 136
def check_files_every
@check_files_every
end
|
Instance Method Details
#delete(pagename, author) ⇒ Object
199
200
201
|
# File 'lib/soks-model.rb', line 199
def delete( pagename, author )
revise( pagename, $MESSAGES[:page_deleted], author )
end
|
#each(exclude_deleted = true) ⇒ Object
172
173
174
|
# File 'lib/soks-model.rb', line 172
def each( exclude_deleted = true )
@pages.each { |name, page| yield [name, page] unless exclude_deleted && page.deleted? }
end
|
#exists?(name) ⇒ Boolean
176
177
178
|
# File 'lib/soks-model.rb', line 176
def exists?( name )
@pages.include?( name.downcase ) && !page_named( name ).deleted?
end
|
#move(old_pagename, new_pagename, author) ⇒ Object
186
187
188
189
190
191
|
# File 'lib/soks-model.rb', line 186
def move( old_pagename, new_pagename, author )
old_content = page(old_pagename).content
revise( old_pagename, "#{$MESSAGES[:content_moved_to]} [[#{new_pagename}]]", author )
revise( new_pagename, "#{$MESSAGES[:content_moved_from]} [[#{old_pagename}]]", author )
revise( new_pagename, old_content, author )
end
|
#page(name) ⇒ Object
168
169
170
|
# File 'lib/soks-model.rb', line 168
def page( name )
page_named( name )|| new_page( name, :empty )
end
|
#revise(pagename, content, author) ⇒ Object
180
181
182
183
184
|
# File 'lib/soks-model.rb', line 180
def revise( pagename, content, author )
raise "Sorry! Shutting down..." if @shutting_down
check_disk_for_updated_page pagename
mutate( pagename ) { |page| page.revise( content, author ) }
end
|
#rollback(pagename, number, author) ⇒ Object
193
194
195
196
197
|
# File 'lib/soks-model.rb', line 193
def rollback( pagename, number, author )
raise "Sorry! Shutting down..." if @shutting_down
check_disk_for_updated_page pagename
mutate( pagename ) { |page| page.rollback( number, author ) }
end
|
#shutdown ⇒ Object
161
162
163
164
165
166
|
# File 'lib/soks-model.rb', line 161
def shutdown
notify :shutdown
sleep(1) until event_queue.empty?
@shutting_down = true save_cache(CACHE_NAME, @pages)
end
|
#start ⇒ Object
155
156
157
158
159
|
# File 'lib/soks-model.rb', line 155
def start
load_all_pages
start_watching_files
setup_periodic_notifications
end
|
#wipe_from_disk(pagename) ⇒ Object
203
204
205
206
207
208
209
210
|
# File 'lib/soks-model.rb', line 203
def wipe_from_disk( pagename )
page = page_named( pagename )
raise "Page not deleted!" unless page.deleted?
page.content_lock.synchronize do
delete_files_for_page( pagename.downcase )
@pages.delete( pagename.downcase )
end
end
|