Class: WikiContentVersion

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/wiki_content_version.rb

Instance Method Summary collapse

Instance Method Details

#attachmentsObject


82
83
84
# File 'app/models/wiki_content_version.rb', line 82

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

#current_version?Boolean

Return true if the content is the current page content

Returns:

  • (Boolean)

87
88
89
# File 'app/models/wiki_content_version.rb', line 87

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

#nextObject

Returns the next version or nil


100
101
102
103
104
105
# File 'app/models/wiki_content_version.rb', line 100

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


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

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

#projectObject


78
79
80
# File 'app/models/wiki_content_version.rb', line 78

def project
  page.project
end

#textObject


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

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


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/wiki_content_version.rb', line 47

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