aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_text/serialization.rb
blob: ac2b0602d525ce8620eabc15bf2586e75337c88e (plain) (blame)
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
module ActionText
  module Serialization
    extend ActiveSupport::Concern

    class_methods do
      def load(content)
        new(content) if content
      end

      def dump(content)
        case content
        when nil
          nil
        when self
          content.to_html
        else
          new(content).to_html
        end
      end
    end

    # Marshal compatibility

    class_methods do
      alias_method :_load, :load
    end

    def _dump(*)
      self.class.dump(self)
    end
  end
end