Class: Vident2::Internals::ActionBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vident2/internals/action_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Fluent chain returned by ‘action(…)` inside a `stimulus do` block. Each method mutates state and returns `self` so chains compose:

action(:submit).on(:form).modifier(:prevent).keyboard("enter")

At ‘to_declaration` time the captured state is folded into a Hash descriptor that the `Stimulus::Action` parser already understands. If no chain method was called, the raw args pass through untouched so existing `action :click` / `action [:click, :handle]` callsites behave exactly as before.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ActionBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ActionBuilder.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vident2/internals/action_builder.rb', line 19

def initialize(*args)
  @args = args
  @event = nil
  @method_name = nil
  @modifiers = nil
  @keyboard = nil
  @window = false
  @controller_ref = nil
  @when_proc = nil
  @touched = false
end

Instance Method Details

#keyboard(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
# File 'lib/vident2/internals/action_builder.rb', line 49

def keyboard(str)
  @keyboard = str
  @touched = true
  self
end

#method(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
# File 'lib/vident2/internals/action_builder.rb', line 37

def method(name)
  @method_name = name
  @touched = true
  self
end

#modifier(*mods) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
# File 'lib/vident2/internals/action_builder.rb', line 43

def modifier(*mods)
  (@modifiers ||= []).concat(mods)
  @touched = true
  self
end

#on(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
# File 'lib/vident2/internals/action_builder.rb', line 31

def on(event)
  @event = event
  @touched = true
  self
end

#on_controller(ref) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
64
65
# File 'lib/vident2/internals/action_builder.rb', line 61

def on_controller(ref)
  @controller_ref = ref
  @touched = true
  self
end

#to_declarationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
75
# File 'lib/vident2/internals/action_builder.rb', line 72

def to_declaration
  return Declaration.new(args: @args.freeze, when_proc: @when_proc, meta: {}.freeze) unless @touched
  Declaration.new(args: [build_descriptor].freeze, when_proc: @when_proc, meta: {}.freeze)
end

#when(callable = nil, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
70
# File 'lib/vident2/internals/action_builder.rb', line 67

def when(callable = nil, &block)
  @when_proc = block || callable
  self
end

#windowObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
# File 'lib/vident2/internals/action_builder.rb', line 55

def window
  @window = true
  @touched = true
  self
end