Class: Vizcore::DSL::ReactionBuilder
- Inherits:
-
Object
- Object
- Vizcore::DSL::ReactionBuilder
- Defined in:
- lib/vizcore/dsl/reaction_builder.rb
Overview
Collects high-level ‘react_to` DSL entries and converts them to mappings.
Instance Method Summary collapse
-
#change(target, **options) ⇒ void
Continuously map the reaction source to a target parameter.
-
#evaluate { ... } ⇒ Array<Hash>
Evaluate a ‘react_to` block.
-
#initialize(mapping_factory:) ⇒ ReactionBuilder
constructor
A new instance of ReactionBuilder.
-
#trigger(target, **options) ⇒ void
Map the reaction source to an event-like target parameter.
Constructor Details
#initialize(mapping_factory:) ⇒ ReactionBuilder
Returns a new instance of ReactionBuilder.
8 9 10 11 |
# File 'lib/vizcore/dsl/reaction_builder.rb', line 8 def initialize(mapping_factory:) @mapping_factory = mapping_factory @mappings = [] end |
Instance Method Details
#change(target, **options) ⇒ void
This method returns an undefined value.
Continuously map the reaction source to a target parameter.
30 31 32 |
# File 'lib/vizcore/dsl/reaction_builder.rb', line 30 def change(target, **) @mappings << @mapping_factory.call(target, ) end |
#evaluate { ... } ⇒ Array<Hash>
Evaluate a ‘react_to` block.
18 19 20 21 22 23 |
# File 'lib/vizcore/dsl/reaction_builder.rb', line 18 def evaluate(&block) instance_eval(&block) if block raise ArgumentError, "react_to requires at least one change or trigger" if @mappings.empty? @mappings.map(&:dup) end |
#trigger(target, **options) ⇒ void
This method returns an undefined value.
Map the reaction source to an event-like target parameter.
39 40 41 |
# File 'lib/vizcore/dsl/reaction_builder.rb', line 39 def trigger(target, **) change(target, **) end |