rails--rails/lib/active_text/attachable.rb

25 lines
650 B
Ruby
Raw Normal View History

2018-02-08 00:26:19 +00:00
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