Class: MediaWiki::FakeWiki::ApiPages
- Inherits:
-
Object
- Object
- MediaWiki::FakeWiki::ApiPages
- Defined in:
- lib/media_wiki/fake_wiki.rb
Instance Method Summary collapse
- #add(title, content, redirect = false) ⇒ Object
- #add_namespace(id, prefix) ⇒ Object
- #delete(title) ⇒ Object
- #get(title) ⇒ Object
-
#initialize ⇒ ApiPages
constructor
A new instance of ApiPages.
- #list(prefix) ⇒ Object
- #namespaces_by_id ⇒ Object
- #namespaces_by_prefix ⇒ Object
- #search(searchkey, namespaces) ⇒ Object
- #undelete(title) ⇒ Object
Constructor Details
#initialize ⇒ ApiPages
Returns a new instance of ApiPages.
485 486 487 488 489 |
# File 'lib/media_wiki/fake_wiki.rb', line 485 def initialize @page_id = 0 @pages = {} @namespaces = { "" => 0 } end |
Instance Method Details
#add(title, content, redirect = false) ⇒ Object
503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/media_wiki/fake_wiki.rb', line 503 def add(title, content, redirect=false) @page_id += 1 dummy, prefix = title.split(":", 2).reverse @pages[title] = { :pageid => @page_id, :namespace => namespaces_by_prefix[prefix || ""], :title => title, :content => content, :redirect => redirect } end |
#add_namespace(id, prefix) ⇒ Object
491 492 493 |
# File 'lib/media_wiki/fake_wiki.rb', line 491 def add_namespace(id, prefix) @namespaces[prefix] = id end |
#delete(title) ⇒ Object
532 533 534 |
# File 'lib/media_wiki/fake_wiki.rb', line 532 def delete(title) @pages.delete(title) end |
#get(title) ⇒ Object
515 516 517 |
# File 'lib/media_wiki/fake_wiki.rb', line 515 def get(title) @pages[title] end |
#list(prefix) ⇒ Object
519 520 521 522 523 |
# File 'lib/media_wiki/fake_wiki.rb', line 519 def list(prefix) @pages.select do |key, page| key =~ /^#{prefix}/ end end |
#namespaces_by_id ⇒ Object
499 500 501 |
# File 'lib/media_wiki/fake_wiki.rb', line 499 def namespaces_by_id @namespaces.invert end |
#namespaces_by_prefix ⇒ Object
495 496 497 |
# File 'lib/media_wiki/fake_wiki.rb', line 495 def namespaces_by_prefix @namespaces end |
#search(searchkey, namespaces) ⇒ Object
525 526 527 528 529 530 |
# File 'lib/media_wiki/fake_wiki.rb', line 525 def search(searchkey, namespaces) raise ApiError.new("srparam-search", "empty search string is not allowed") if searchkey.empty? @pages.select do |key, page| page[:content] =~ /#{searchkey}/ and namespaces.include? page[:namespace].to_s end end |
#undelete(title) ⇒ Object
536 537 538 539 540 541 542 543 |
# File 'lib/media_wiki/fake_wiki.rb', line 536 def undelete(title) if @pages[title] 0 else add(title, "Undeleted content") 1 end end |