Class: Vident::StimulusAction

Inherits:
StimulusAttributeBase show all
Defined in:
lib/vident/stimulus_action.rb

Defined Under Namespace

Classes: Descriptor

Constant Summary collapse

VALID_OPTIONS =
[:once, :prevent, :stop, :passive, :"!passive", :capture, :self].freeze

Instance Attribute Summary collapse

Attributes inherited from StimulusAttributeBase

#implied_controller

Instance Method Summary collapse

Methods inherited from StimulusAttributeBase

#implied_controller_name, #implied_controller_path, #inspect, js_name, stimulize_path, #to_h

Constructor Details

#initialize(*args, implied_controller: nil) ⇒ StimulusAction

Returns a new instance of StimulusAction.



22
23
24
25
26
27
# File 'lib/vident/stimulus_action.rb', line 22

def initialize(*args, implied_controller: nil)
  @options = []
  @keyboard = nil
  @window = false
  super
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



20
21
22
# File 'lib/vident/stimulus_action.rb', line 20

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



20
21
22
# File 'lib/vident/stimulus_action.rb', line 20

def controller
  @controller
end

#eventObject (readonly)

Returns the value of attribute event.



20
21
22
# File 'lib/vident/stimulus_action.rb', line 20

def event
  @event
end

#keyboardObject (readonly)

Returns the value of attribute keyboard.



20
21
22
# File 'lib/vident/stimulus_action.rb', line 20

def keyboard
  @keyboard
end

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/vident/stimulus_action.rb', line 20

def options
  @options
end

#windowObject (readonly)

Returns the value of attribute window.



20
21
22
# File 'lib/vident/stimulus_action.rb', line 20

def window
  @window
end

Instance Method Details

#data_attribute_nameObject



43
# File 'lib/vident/stimulus_action.rb', line 43

def data_attribute_name = "action"

#data_attribute_valueObject



45
# File 'lib/vident/stimulus_action.rb', line 45

def data_attribute_value = to_s

#to_sObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vident/stimulus_action.rb', line 29

def to_s
  head =
    if @event
      ev = @event.to_s
      ev = "#{ev}.#{@keyboard}" if @keyboard
      ev = "#{ev}#{@options.map { |o| ":#{o}" }.join}" if @options.any?
      ev = "#{ev}@window" if @window
      "#{ev}->"
    else
      ""
    end
  "#{head}#{@controller}##{@action}"
end