Class: WikiContentVersion

Inherits:
ApplicationRecord show all
Defined in:
app/models/wiki_content_version.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

human_attribute_name

Instance Method Details

#attachmentsObject



94
95
96
# File 'app/models/wiki_content_version.rb', line 94

def attachments
  page.nil? ? [] : page.attachments
end

#current_version?Boolean

Return true if the content is the current page content

Returns:

  • (Boolean)


99
100
101
# File 'app/models/wiki_content_version.rb', line 99

def current_version?
  page.content.version == self.version
end

#nextObject

Returns the next version or nil



112
113
114
115
116
117
# File 'app/models/wiki_content_version.rb', line 112

def next
  @next ||= WikiContentVersion.
    reorder(version: :asc).
    includes(:author).
    where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first
end

#previousObject

Returns the previous version or nil



104
105
106
107
108
109
# File 'app/models/wiki_content_version.rb', line 104

def previous
  @previous ||= WikiContentVersion.
    reorder(version: :desc).
    includes(:author).
    where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first
end

#projectObject



90
91
92
# File 'app/models/wiki_content_version.rb', line 90

def project
  page.project
end

#textObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/wiki_content_version.rb', line 77

def text
  @text ||= begin
    str = case compression
          when 'gzip'
            Zlib::Inflate.inflate(data)
          else
            # uncompressed data
            data
          end
    (+str).force_encoding('UTF-8')
  end
end

#text=(plain) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/wiki_content_version.rb', line 60

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