aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_text/attachable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/active_text/attachable.rb')
-rw-r--r--lib/active_text/attachable.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/active_text/attachable.rb b/lib/active_text/attachable.rb
new file mode 100644
index 0000000000..445ee30605
--- /dev/null
+++ b/lib/active_text/attachable.rb
@@ -0,0 +1,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