Class: WikiContentVersion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WikiContentVersion
- Defined in:
- app/models/wiki_content_version.rb
Overview
Instance Method Summary collapse
- #attachments ⇒ Object
-
#current_version? ⇒ Boolean
Return true if the content is the current page content.
-
#next ⇒ Object
Returns the next version or nil.
-
#previous ⇒ Object
Returns the previous version or nil.
- #project ⇒ Object
- #text ⇒ Object
- #text=(plain) ⇒ Object
Instance Method Details
#attachments ⇒ Object
80 81 82 |
# File 'app/models/wiki_content_version.rb', line 80 def page.nil? ? [] : page. end |
#current_version? ⇒ Boolean
Return true if the content is the current page content
85 86 87 |
# File 'app/models/wiki_content_version.rb', line 85 def current_version? page.content.version == self.version end |
#next ⇒ Object
Returns the next version or nil
98 99 100 101 102 103 |
# File 'app/models/wiki_content_version.rb', line 98 def next @next ||= WikiContentVersion. reorder(version: :asc). includes(:author). where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first end |
#previous ⇒ Object
Returns the previous version or nil
90 91 92 93 94 95 |
# File 'app/models/wiki_content_version.rb', line 90 def previous @previous ||= WikiContentVersion. reorder(version: :desc). includes(:author). where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first end |
#project ⇒ Object
76 77 78 |
# File 'app/models/wiki_content_version.rb', line 76 def project page.project end |
#text ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/wiki_content_version.rb', line 62 def text @text ||= begin str = case compression when 'gzip' Zlib::Inflate.inflate(data) else # uncompressed data data end str.force_encoding("UTF-8") str end end |
#text=(plain) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/wiki_content_version.rb', line 45 def text=(plain) case Setting.wiki_compression when 'gzip' begin self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION) self.compression = 'gzip' rescue self.data = plain self.compression = '' end else self.data = plain self.compression = '' end plain end |