Class: Vident::Internals::ActionBuilder
- Inherits:
-
Object
- Object
- Vident::Internals::ActionBuilder
- Defined in:
- lib/vident/internals/action_builder.rb
Overview
Fluent builder returned by ‘action(…)`. If no chain methods are called, raw args pass through untouched so bare `action :click` still works.
Constant Summary collapse
- KWARG_KEYS =
%i[on call_method modifier keyboard window on_controller when].freeze
Instance Method Summary collapse
- #call_method(name) ⇒ Object
-
#initialize(*args, **meta) ⇒ ActionBuilder
constructor
A new instance of ActionBuilder.
- #keyboard(str) ⇒ Object
- #modifier(*mods) ⇒ Object
- #on(event) ⇒ Object
- #on_controller(ref) ⇒ Object
- #to_declaration ⇒ Object
- #when(callable = nil, &block) ⇒ Object
- #window ⇒ Object
Constructor Details
#initialize(*args, **meta) ⇒ ActionBuilder
Returns a new instance of ActionBuilder.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vident/internals/action_builder.rb', line 12 def initialize(*args, **) @args = args unknown = .keys - KWARG_KEYS raise ArgumentError, "action: unknown option(s) #{unknown.inspect}. Valid: #{KWARG_KEYS.inspect}" unless unknown.empty? @event = [:on] @method_name = [:call_method] @modifiers = .key?(:modifier) ? Array([:modifier]) : nil @keyboard = [:keyboard] @window = .fetch(:window, false) @controller_ref = [:on_controller] @when_proc = [:when] @touched = !.empty? end |
Instance Method Details
#call_method(name) ⇒ Object
33 34 35 36 37 |
# File 'lib/vident/internals/action_builder.rb', line 33 def call_method(name) @method_name = name @touched = true self end |
#keyboard(str) ⇒ Object
45 46 47 48 49 |
# File 'lib/vident/internals/action_builder.rb', line 45 def keyboard(str) @keyboard = str @touched = true self end |
#modifier(*mods) ⇒ Object
39 40 41 42 43 |
# File 'lib/vident/internals/action_builder.rb', line 39 def modifier(*mods) (@modifiers ||= []).concat(mods) @touched = true self end |
#on(event) ⇒ Object
27 28 29 30 31 |
# File 'lib/vident/internals/action_builder.rb', line 27 def on(event) @event = event @touched = true self end |
#on_controller(ref) ⇒ Object
57 58 59 60 61 |
# File 'lib/vident/internals/action_builder.rb', line 57 def on_controller(ref) @controller_ref = ref @touched = true self end |
#to_declaration ⇒ Object
68 69 70 71 |
# File 'lib/vident/internals/action_builder.rb', line 68 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
63 64 65 66 |
# File 'lib/vident/internals/action_builder.rb', line 63 def when(callable = nil, &block) @when_proc = block || callable self end |
#window ⇒ Object
51 52 53 54 55 |
# File 'lib/vident/internals/action_builder.rb', line 51 def window @window = true @touched = true self end |