Class: StimulusReflex::Broadcasters::Update

Inherits:
Object
  • Object
show all
Includes:
CableReady::Identifiable
Defined in:
lib/stimulus_reflex/broadcasters/update.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, value, reflex) ⇒ Update

Returns a new instance of Update.



8
9
10
11
12
# File 'lib/stimulus_reflex/broadcasters/update.rb', line 8

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

Instance Method Details

#htmlObject



18
19
20
21
22
23
# File 'lib/stimulus_reflex/broadcasters/update.rb', line 18

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

#selectorObject



14
15
16
# File 'lib/stimulus_reflex/broadcasters/update.rb', line 14

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