lib/cable_ready/identifiable.rb in cable_ready-5.0.0.pre1 vs lib/cable_ready/identifiable.rb in cable_ready-5.0.0.pre2
- old
+ new
@@ -1,19 +1,30 @@
# frozen_string_literal: true
module CableReady
module Identifiable
def dom_id(record, prefix = nil)
+ return record.to_dom_selector if record.respond_to?(:to_dom_selector)
+
prefix = prefix.to_s.strip if prefix
- id = if record.is_a?(ActiveRecord::Relation)
+ id = if record.respond_to?(:to_dom_id)
+ record.to_dom_id
+ elsif record.is_a?(ActiveRecord::Relation)
[prefix, record.model_name.plural].compact.join("_")
elsif record.is_a?(ActiveRecord::Base)
ActionView::RecordIdentifier.dom_id(record, prefix)
else
[prefix, record.to_s.strip].compact.join("_")
end
- "##{id}".squeeze("#").strip
+ "##{id}".squeeze("#").strip.downcase
+ end
+
+ def identifiable?(obj)
+ obj.respond_to?(:to_dom_selector) ||
+ obj.respond_to?(:to_dom_id) ||
+ obj.is_a?(ActiveRecord::Relation) ||
+ obj.is_a?(ActiveRecord::Base)
end
end
end