Class: Vizcore::DSL::LayerGroupBuilder
- Inherits:
-
Object
- Object
- Vizcore::DSL::LayerGroupBuilder
- Defined in:
- lib/vizcore/dsl/layer_group_builder.rb
Overview
Collects related layers and applies shared layer parameters.
Instance Method Summary collapse
- #blend(value) ⇒ Symbol
-
#evaluate { ... } ⇒ Vizcore::DSL::LayerGroupBuilder
Evaluate a group block.
-
#initialize(name:, styles: {}, defaults: {}) ⇒ LayerGroupBuilder
constructor
A new instance of LayerGroupBuilder.
-
#layer(name) { ... } ⇒ void
Define one layer in this group.
-
#method_missing(method_name, *args, &block) ⇒ Object
private
Stores dynamic one-argument setters into shared group params.
-
#palette(*colors) ⇒ Array<String>
Store an ordered color palette shared by nested layers.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#to_a ⇒ Array<Hash>
Serialized nested layers.
-
#use_style(name) ⇒ Hash
Merge a named style into this group’s shared params.
Constructor Details
#initialize(name:, styles: {}, defaults: {}) ⇒ LayerGroupBuilder
Returns a new instance of LayerGroupBuilder.
12 13 14 15 16 17 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 12 def initialize(name:, styles: {}, defaults: {}) @name = name.to_sym @styles = styles @params = deep_dup(defaults) @layers = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &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.
Stores dynamic one-argument setters into shared group params.
72 73 74 75 76 77 78 79 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 72 def method_missing(method_name, *args, &block) if block.nil? && args.length == 1 @params[method_name.to_sym] = args.first return args.first end super end |
Instance Method Details
#blend(value) ⇒ Symbol
41 42 43 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 41 def blend(value) @params[:blend] = value.to_sym end |
#evaluate { ... } ⇒ Vizcore::DSL::LayerGroupBuilder
Evaluate a group block.
23 24 25 26 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 23 def evaluate(&block) instance_eval(&block) if block self end |
#layer(name) { ... } ⇒ void
This method returns an undefined value.
Define one layer in this group.
33 34 35 36 37 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 33 def layer(name, &block) builder = LayerBuilder.new(name: name, styles: @styles, defaults: layer_defaults) builder.evaluate(&block) @layers << builder.to_h end |
#palette(*colors) ⇒ Array<String>
Store an ordered color palette shared by nested layers.
50 51 52 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 50 def palette(*colors) @params[:palette] = normalize_palette(colors) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
81 82 83 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 81 def respond_to_missing?(method_name, include_private = false) @params.key?(method_name.to_sym) || super end |
#to_a ⇒ Array<Hash>
Returns serialized nested layers.
66 67 68 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 66 def to_a @layers.map { |layer| deep_dup(layer) } end |
#use_style(name) ⇒ Hash
Merge a named style into this group’s shared params.
59 60 61 62 63 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 59 def use_style(name) style_name = name.to_sym style_params = @styles.fetch(style_name) { raise ArgumentError, "unknown style: #{style_name}" } @params.merge!(deep_dup(style_params)) end |