Class: Vident2::Internals::DSL Private
- Inherits:
-
Object
- Object
- Vident2::Internals::DSL
- Defined in:
- lib/vident2/internals/dsl.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.
Block receiver for ‘stimulus do … end`. Records each primitive call as one or more `Declaration` raw entries; `finalize` folds them into a frozen `Declarations` aggregate.
Parsing into ‘Stimulus::*` value objects is deferred to the Resolver — this class stores only raw argument tuples.
Instance Attribute Summary collapse
- #caller_location ⇒ Object readonly private
Instance Method Summary collapse
-
#action(*args) ⇒ Object
private
Returns an ‘ActionBuilder` so users can fluent-chain `.on(:event).modifier(:prevent).keyboard(“ctrl+s”).window.when { … }`.
-
#actions(*names) ⇒ Object
private
Array in the plural form splats into the singular parser (matching V1’s plural→singular forwarding) so ‘actions [:click, :handle]` records a single Action entry with event+method rather than two separate Actions.
- #class_map(name, *args, **meta) ⇒ Object private
- #classes(**hash) ⇒ Object private
-
#controller(*args, **meta) ⇒ Object
private
Optional ‘as: :alias` captured in meta for the Resolver.
-
#controllers(*args) ⇒ Object
private
Each arg becomes one controller entry.
-
#initialize(caller_location: nil) ⇒ DSL
constructor
private
A new instance of DSL.
- #outlet(name, *args, **meta) ⇒ Object private
-
#outlets(positional = nil, **hash) ⇒ Object
private
Outlets accept a positional Hash (for keys like ‘“admin–users”` that can’t be a Ruby kwarg) plus kwargs.
- #param(name, *args, **meta) ⇒ Object private
- #params(**hash) ⇒ Object private
-
#target(*args) ⇒ Object
private
Returns a ‘TargetBuilder` so users can chain `.when { … }` for conditional inclusion.
- #targets(*names) ⇒ Object private
-
#to_declarations ⇒ Object
private
Returns a frozen Declarations snapshot of what this block received.
-
#value(name, *args, **meta) ⇒ Object
private
‘value(:url, “x”)`, `value(:url, -> { … })`, `value(:count, static: 0)`, `value(:clicked_count, from_prop: true)`.
- #values(**hash) ⇒ Object private
- #values_from_props(*names) ⇒ Object private
Constructor Details
#initialize(caller_location: nil) ⇒ DSL
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 DSL.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vident2/internals/dsl.rb', line 20 def initialize(caller_location: nil) @caller_location = caller_location @controllers = [] @actions = [] @targets = [] @outlets = [] @values = [] @params = [] @class_maps = [] @values_from_props = [] end |
Instance Attribute Details
#caller_location ⇒ Object (readonly)
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.
18 19 20 |
# File 'lib/vident2/internals/dsl.rb', line 18 def caller_location @caller_location end |
Instance Method Details
#action(*args) ⇒ 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.
Returns an ‘ActionBuilder` so users can fluent-chain `.on(:event).modifier(:prevent).keyboard(“ctrl+s”).window.when { … }`. If no chain methods are called, the raw args pass through unchanged.
122 123 124 125 126 |
# File 'lib/vident2/internals/dsl.rb', line 122 def action(*args) builder = ActionBuilder.new(*args) @actions << builder builder end |
#actions(*names) ⇒ 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.
Array in the plural form splats into the singular parser (matching V1’s plural→singular forwarding) so ‘actions [:click, :handle]` records a single Action entry with event+method rather than two separate Actions.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vident2/internals/dsl.rb', line 53 def actions(*names) names.each do |name| case name in Array action(*name) else action(name) end end self end |
#class_map(name, *args, **meta) ⇒ 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.
156 157 158 159 160 |
# File 'lib/vident2/internals/dsl.rb', line 156 def class_map(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@class_maps, entry) self end |
#classes(**hash) ⇒ 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.
87 88 89 90 |
# File 'lib/vident2/internals/dsl.rb', line 87 def classes(**hash) hash.each { |k, v| record_keyed(@class_maps, k, v) } self end |
#controller(*args, **meta) ⇒ 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.
Optional ‘as: :alias` captured in meta for the Resolver.
114 115 116 117 |
# File 'lib/vident2/internals/dsl.rb', line 114 def controller(*args, **) @controllers << Declaration.of(*args, **) self end |
#controllers(*args) ⇒ 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.
Each arg becomes one controller entry. An Array arg is splatted into positional args for a single controller (e.g. a tuple ‘[path, :alias]`); anything else is treated as a path.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vident2/internals/dsl.rb', line 37 def controllers(*args) args.each do |arg| case arg in Array controller(*arg) else controller(arg) end end self end |
#outlet(name, *args, **meta) ⇒ 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.
150 151 152 153 154 |
# File 'lib/vident2/internals/dsl.rb', line 150 def outlet(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@outlets, entry) self end |
#outlets(positional = nil, **hash) ⇒ 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.
Outlets accept a positional Hash (for keys like ‘“admin–users”` that can’t be a Ruby kwarg) plus kwargs. Order: positional first, kwargs after — last-write wins on duplicates per the keyed merge rule.
96 97 98 99 100 101 102 103 104 |
# File 'lib/vident2/internals/dsl.rb', line 96 def outlets(positional = nil, **hash) if positional.is_a?(Hash) positional.each { |k, v| record_keyed(@outlets, k, v) } elsif !positional.nil? raise ArgumentError, "outlets: positional arg must be a Hash, got #{positional.class}" end hash.each { |k, v| record_keyed(@outlets, k, v) } self end |
#param(name, *args, **meta) ⇒ 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.
144 145 146 147 148 |
# File 'lib/vident2/internals/dsl.rb', line 144 def param(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@params, entry) self end |
#params(**hash) ⇒ 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.
82 83 84 85 |
# File 'lib/vident2/internals/dsl.rb', line 82 def params(**hash) hash.each { |k, v| record_keyed(@params, k, v) } self end |
#target(*args) ⇒ 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.
Returns a ‘TargetBuilder` so users can chain `.when { … }` for conditional inclusion.
130 131 132 133 134 |
# File 'lib/vident2/internals/dsl.rb', line 130 def target(*args) builder = TargetBuilder.new(*args) @targets << builder builder end |
#targets(*names) ⇒ 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.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vident2/internals/dsl.rb', line 65 def targets(*names) names.each do |name| case name in Array target(*name) else target(name) end end self end |
#to_declarations ⇒ 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.
Returns a frozen Declarations snapshot of what this block received. Called once the block finishes executing.
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/vident2/internals/dsl.rb', line 166 def to_declarations Declarations.new( controllers: @controllers.dup.freeze, actions: @actions.map(&:to_declaration).freeze, targets: @targets.map(&:to_declaration).freeze, outlets: @outlets.dup.freeze, values: @values.dup.freeze, params: @params.dup.freeze, class_maps: @class_maps.dup.freeze, values_from_props: @values_from_props.dup.freeze ).freeze end |
#value(name, *args, **meta) ⇒ 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.
‘value(:url, “x”)`, `value(:url, -> { … })`, `value(:count, static: 0)`, `value(:clicked_count, from_prop: true)`.
138 139 140 141 142 |
# File 'lib/vident2/internals/dsl.rb', line 138 def value(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@values, entry) self end |
#values(**hash) ⇒ 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.
77 78 79 80 |
# File 'lib/vident2/internals/dsl.rb', line 77 def values(**hash) hash.each { |k, v| record_keyed(@values, k, v) } self end |
#values_from_props(*names) ⇒ 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.
106 107 108 109 |
# File 'lib/vident2/internals/dsl.rb', line 106 def values_from_props(*names) @values_from_props.concat(names.map(&:to_sym)) self end |