summaryrefslogtreecommitdiff
path: root/lib/gitlab/git/wiki_page.rb
blob: a06bac4414fd71d412a10e9c3db1e6c6df13837d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Gitlab
  module Git
    class WikiPage
      attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :text_data, :historical

      # This class is meant to be serializable so that it can be constructed
      # by Gitaly and sent over the network to GitLab.
      #
      # Because Gollum::Page is not serializable we must get all the data from
      # 'gollum_page' during initialization, and NOT store it in an instance
      # variable.
      #
      # Note that 'version' is a WikiPageVersion instance which it itself
      # serializable. That means it's OK to store 'version' in an instance
      # variable.
      def initialize(gollum_page, version)
        @url_path = gollum_page.url_path
        @title = gollum_page.title
        @format = gollum_page.format
        @path = gollum_page.path
        @raw_data = gollum_page.raw_data
        @name = gollum_page.name
        @historical = gollum_page.historical?

        @version = version
      end

      def historical?
        @historical
      end

      def text_data
        return @text_data if defined?(@text_data)

        @text_data = @raw_data && Gitlab::EncodingHelper.encode!(@raw_data.dup)
      end
    end
  end
end