aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_text/attachable.rb
blob: 445ee30605e8426a1610f2841595cd60c6aca28e (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
module ActiveText
  module Attachable
    class << self
      def from_node(node)
        if attachable = attachable_from_sgid(node["sgid"])
          attachable
        elsif attachable = ActiveText::Attachables::ContentAttachment.from_node(node)
          attachable
        elsif attachable = ActiveText::Attachables::RemoteImage.from_node(node)
          attachable
        else
          ActiveText::Attachables::MissingAttachable
        end
      end

      private
        def attachable_from_sgid(sgid)
          ::Attachable.from_attachable_sgid(sgid)
        rescue ActiveRecord::RecordNotFound
          nil
        end
    end
  end
end