Sha256: 308d2b21c0e6dd5edd5bec2bbcff78c5dc06e02d05c0386f7d2195c9035d3a06

Contents?: true

Size: 781 Bytes

Versions: 5

Compression:

Stored size: 781 Bytes

Contents

# frozen_string_literal: true

class Object
  def bullet_key
    "#{self.class}:#{bullet_primary_key_value}"
  end

  def bullet_primary_key_value
    return if respond_to?(:persisted?) && !persisted?

    if self.class.respond_to?(:primary_keys) && self.class.primary_keys
      primary_key = self.class.primary_keys
    elsif self.class.respond_to?(:primary_key) && self.class.primary_key
      primary_key = self.class.primary_key
    else
      primary_key = :id
    end

    bullet_join_potential_composite_primary_key(primary_key)
  end

  private

  def bullet_join_potential_composite_primary_key(primary_keys)
    return send(primary_keys) unless primary_keys.is_a?(Enumerable)

    primary_keys.map { |primary_key| send primary_key }
                .join(',')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bullet-7.2.0 lib/bullet/ext/object.rb
bullet-7.1.6 lib/bullet/ext/object.rb
bullet-7.1.5 lib/bullet/ext/object.rb
bullet-7.1.4 lib/bullet/ext/object.rb
bullet-7.1.3 lib/bullet/ext/object.rb