Class: Vident::Internals::DSL
- Inherits:
-
Object
- Object
- Vident::Internals::DSL
- Defined in:
- lib/vident/internals/dsl.rb
Overview
Block receiver for ‘stimulus do … end`. Records raw Declaration entries; parsing into typed Stimulus value objects is deferred to the Resolver.
Instance Attribute Summary collapse
-
#caller_location ⇒ Object
readonly
Returns the value of attribute caller_location.
Instance Method Summary collapse
- #action(*args, **meta) ⇒ Object
- #actions(*names) ⇒ Object
- #class_map(name, *args, **meta) ⇒ Object
- #classes(**hash) ⇒ Object
-
#controller(*args, **meta) ⇒ Object
—- singular forms ——————————————–.
-
#controllers(*args) ⇒ Object
—- plural (kwargs) forms ————————————–.
-
#initialize(caller_location: nil) ⇒ DSL
constructor
A new instance of DSL.
- #outlet(name, *args, **meta) ⇒ Object
-
#outlets(positional = nil, **hash) ⇒ Object
Positional Hash arg supports keys like ‘“admin–users”` that can’t be Ruby kwargs.
- #param(name, *args, **meta) ⇒ Object
- #params(**hash) ⇒ Object
- #target(*args) ⇒ Object
- #targets(*names) ⇒ Object
-
#to_declarations ⇒ Object
—- folding —————————————————-.
- #value(name, *args, **meta) ⇒ Object
- #values(**hash) ⇒ Object
- #values_from_props(*names) ⇒ Object
Constructor Details
#initialize(caller_location: nil) ⇒ DSL
Returns a new instance of DSL.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vident/internals/dsl.rb', line 15 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)
Returns the value of attribute caller_location.
13 14 15 |
# File 'lib/vident/internals/dsl.rb', line 13 def caller_location @caller_location end |
Instance Method Details
#action(*args, **meta) ⇒ Object
103 104 105 106 107 |
# File 'lib/vident/internals/dsl.rb', line 103 def action(*args, **) builder = ActionBuilder.new(*args, **) @actions << builder builder end |
#actions(*names) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vident/internals/dsl.rb', line 41 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
133 134 135 136 137 |
# File 'lib/vident/internals/dsl.rb', line 133 def class_map(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@class_maps, entry) self end |
#classes(**hash) ⇒ Object
75 76 77 78 |
# File 'lib/vident/internals/dsl.rb', line 75 def classes(**hash) hash.each { |k, v| record_keyed(@class_maps, k, v) } self end |
#controller(*args, **meta) ⇒ Object
—- singular forms ——————————————–
98 99 100 101 |
# File 'lib/vident/internals/dsl.rb', line 98 def controller(*args, **) @controllers << Declaration.of(*args, **) self end |
#controllers(*args) ⇒ Object
—- plural (kwargs) forms ————————————–
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vident/internals/dsl.rb', line 29 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
127 128 129 130 131 |
# File 'lib/vident/internals/dsl.rb', line 127 def outlet(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@outlets, entry) self end |
#outlets(positional = nil, **hash) ⇒ Object
Positional Hash arg supports keys like ‘“admin–users”` that can’t be Ruby kwargs.
81 82 83 84 85 86 87 88 89 |
# File 'lib/vident/internals/dsl.rb', line 81 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
121 122 123 124 125 |
# File 'lib/vident/internals/dsl.rb', line 121 def param(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@params, entry) self end |
#params(**hash) ⇒ Object
70 71 72 73 |
# File 'lib/vident/internals/dsl.rb', line 70 def params(**hash) hash.each { |k, v| record_keyed(@params, k, v) } self end |
#target(*args) ⇒ Object
109 110 111 112 113 |
# File 'lib/vident/internals/dsl.rb', line 109 def target(*args) builder = TargetBuilder.new(*args) @targets << builder builder end |
#targets(*names) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vident/internals/dsl.rb', line 53 def targets(*names) names.each do |name| case name in Array target(*name) else target(name) end end self end |
#to_declarations ⇒ Object
—- folding —————————————————-
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/vident/internals/dsl.rb', line 141 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
115 116 117 118 119 |
# File 'lib/vident/internals/dsl.rb', line 115 def value(name, *args, **) entry = [name, Declaration.of(*args, **)] replace_or_append(@values, entry) self end |
#values(**hash) ⇒ Object
65 66 67 68 |
# File 'lib/vident/internals/dsl.rb', line 65 def values(**hash) hash.each { |k, v| record_keyed(@values, k, v) } self end |
#values_from_props(*names) ⇒ Object
91 92 93 94 |
# File 'lib/vident/internals/dsl.rb', line 91 def values_from_props(*names) @values_from_props.concat(names.map(&:to_sym)) self end |