Sha256: b87e3f81ce7d454d12cd5cf8e00889c28e378c8e468da043eda9c360f0696092

Contents?: true

Size: 653 Bytes

Versions: 5

Compression:

Stored size: 653 Bytes

Contents

# frozen_string_literal: true

module StimulusReflex
  module Broadcasters
    class Update
      include CableReady::Identifiable

      def initialize(key, value, reflex)
        @key = key
        @value = value
        @reflex = reflex
      end

      def selector
        @selector ||= identifiable?(@key) ? dom_id(@key) : @key.to_s
      end

      def html
        return @value unless defined?(ActiveRecord)
        html = @reflex.render(@key) if @key.is_a?(ActiveRecord::Base) && @value.nil?
        html = @reflex.render_collection(@key) if @key.is_a?(ActiveRecord::Relation) && @value.nil?
        html || @value
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stimulus_reflex-3.5.0.rc4 lib/stimulus_reflex/broadcasters/update.rb
stimulus_reflex-3.5.0.rc3 lib/stimulus_reflex/broadcasters/update.rb
stimulus_reflex-3.5.0.rc2 lib/stimulus_reflex/broadcasters/update.rb
stimulus_reflex-3.5.0.rc1 lib/stimulus_reflex/broadcasters/update.rb
stimulus_reflex-3.5.0.pre10 lib/stimulus_reflex/broadcasters/update.rb