Module: AbstractWikiService
- Included in:
- WikiService
- Defined in:
- app/models/wiki_service.rb
Instance Attribute Summary collapse
-
#system ⇒ Object
readonly
Returns the value of attribute system.
-
#webs ⇒ Object
readonly
Returns the value of attribute webs.
Instance Method Summary collapse
- #authenticate(password) ⇒ Object
- #create_web(name, address, password = nil) ⇒ Object
- #delete_web(address) ⇒ Object
- #edit_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, password = nil, published = false, brackets_only = false, count_pages = false, allow_uploads = true, max_upload_size = nil) ⇒ Object
- #file_yard(web) ⇒ Object
- #init_wiki_service ⇒ Object
- #read_page(web_address, page_name) ⇒ Object
- #remove_orphaned_pages(web_address) ⇒ Object
- #revise_page(web_address, page_name, content, revised_on, author) ⇒ Object
- #rollback_page(web_address, page_name, revision_number, created_at, author_id = nil) ⇒ Object
- #setup(password, web_name, web_address) ⇒ Object
- #setup? ⇒ Boolean
- #storage_path ⇒ Object
- #write_page(web_address, page_name, content, written_on, author) ⇒ Object
Instance Attribute Details
#system ⇒ Object (readonly)
Returns the value of attribute system.
15 16 17 |
# File 'app/models/wiki_service.rb', line 15 def system @system end |
#webs ⇒ Object (readonly)
Returns the value of attribute webs.
15 16 17 |
# File 'app/models/wiki_service.rb', line 15 def webs @webs end |
Instance Method Details
#authenticate(password) ⇒ Object
17 18 19 20 |
# File 'app/models/wiki_service.rb', line 17 def authenticate(password) # system['password'] variant is for compatibility with storages from older versions password == (@system[:password] || @system['password'] || 'instiki') end |
#create_web(name, address, password = nil) ⇒ Object
22 23 24 |
# File 'app/models/wiki_service.rb', line 22 def create_web(name, address, password = nil) @webs[address] = Web.new(self, name, address, password) unless @webs[address] end |
#delete_web(address) ⇒ Object
26 27 28 |
# File 'app/models/wiki_service.rb', line 26 def delete_web(address) @webs[address] = nil end |
#edit_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, password = nil, published = false, brackets_only = false, count_pages = false, allow_uploads = true, max_upload_size = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/wiki_service.rb', line 41 def edit_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, password = nil, published = false, brackets_only = false, count_pages = false, allow_uploads = true, max_upload_size = nil) if not @webs.key? old_address raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist") end if old_address != new_address if @webs.key? new_address raise Instiki::ValidationError.new("There is already a web with address '#{new_address}'") end @webs[new_address] = @webs[old_address] @webs.delete(old_address) @webs[new_address].address = new_address end web = @webs[new_address] web.refresh_revisions if settings_changed?(web, markup, safe_mode, brackets_only) web.name, web.markup, web.color, web.additional_style, web.safe_mode = name, markup, color, additional_style, safe_mode web.password, web.published, web.brackets_only, web.count_pages = password, published, brackets_only, count_pages, allow_uploads web.allow_uploads, web.max_upload_size = allow_uploads, max_upload_size.to_i end |
#file_yard(web) ⇒ Object
30 31 32 33 34 |
# File 'app/models/wiki_service.rb', line 30 def file_yard(web) raise "Web #{@web.name} does not belong to this wiki service" unless @webs.values.include?(web) # TODO cache FileYards FileYard.new("#{self.storage_path}/#{web.address}", web.max_upload_size) end |
#init_wiki_service ⇒ Object
36 37 38 39 |
# File 'app/models/wiki_service.rb', line 36 def init_wiki_service @webs = {} @system = {} end |
#read_page(web_address, page_name) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/wiki_service.rb', line 69 def read_page(web_address, page_name) ApplicationController.logger.debug "Reading page '#{page_name}' from web '#{web_address}'" web = @webs[web_address] if web.nil? ApplicationController.logger.debug "Web '#{web_address}' not found" return nil else page = web.pages[page_name] ApplicationController.logger.debug "Page '#{page_name}' #{page.nil? ? 'not' : ''} found" return page end end |
#remove_orphaned_pages(web_address) ⇒ Object
82 83 84 |
# File 'app/models/wiki_service.rb', line 82 def remove_orphaned_pages(web_address) @webs[web_address].remove_pages(@webs[web_address].select.orphaned_pages) end |
#revise_page(web_address, page_name, content, revised_on, author) ⇒ Object
86 87 88 89 |
# File 'app/models/wiki_service.rb', line 86 def revise_page(web_address, page_name, content, revised_on, ) page = read_page(web_address, page_name) page.revise(content, revised_on, ) end |
#rollback_page(web_address, page_name, revision_number, created_at, author_id = nil) ⇒ Object
91 92 93 94 |
# File 'app/models/wiki_service.rb', line 91 def rollback_page(web_address, page_name, revision_number, created_at, = nil) page = read_page(web_address, page_name) page.rollback(revision_number, created_at, ) end |
#setup(password, web_name, web_address) ⇒ Object
96 97 98 99 |
# File 'app/models/wiki_service.rb', line 96 def setup(password, web_name, web_address) @system[:password] = password create_web(web_name, web_address) end |
#setup? ⇒ Boolean
101 102 103 |
# File 'app/models/wiki_service.rb', line 101 def setup? not (@webs.empty?) end |
#storage_path ⇒ Object
105 106 107 |
# File 'app/models/wiki_service.rb', line 105 def storage_path self.class.storage_path end |
#write_page(web_address, page_name, content, written_on, author) ⇒ Object
109 110 111 |
# File 'app/models/wiki_service.rb', line 109 def write_page(web_address, page_name, content, written_on, ) @webs[web_address].add_page(page_name, content, written_on, ) end |