Class: LiveComponent::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/live_component/action.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_name, event_name) ⇒ Action

Returns a new instance of Action.



5
6
7
8
# File 'lib/live_component/action.rb', line 5

def initialize(controller_name, event_name)
  @controller_name = controller_name
  @event_name = event_name
end

Class Method Details

.attr_nameObject



15
16
17
# File 'lib/live_component/action.rb', line 15

def self.attr_name
  :actions
end

Instance Method Details

#attr_nameObject



19
20
21
# File 'lib/live_component/action.rb', line 19

def attr_name
  self.class.attr_name
end

#call(method_name) ⇒ Object



10
11
12
13
# File 'lib/live_component/action.rb', line 10

def call(method_name)
  @method_name = method_name
  self
end

#to_attributesObject



23
24
25
26
27
28
29
# File 'lib/live_component/action.rb', line 23

def to_attributes
  {}.tap do |attrs|
    if @method_name
      attrs[:"data-action"] = "#{@event_name}->#{@controller_name}##{@method_name}"
    end
  end
end