Class: Vizcore::DSL::LayerGroupBuilder
- Inherits:
-
Object
- Object
- Vizcore::DSL::LayerGroupBuilder
- Includes:
- ColorHelpers
- 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: {}, mapping_presets: {}, strict: false) ⇒ 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.
Methods included from ColorHelpers
Constructor Details
#initialize(name:, styles: {}, defaults: {}, mapping_presets: {}, strict: false) ⇒ LayerGroupBuilder
Returns a new instance of LayerGroupBuilder.
17 18 19 20 21 22 23 24 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 17 def initialize(name:, styles: {}, defaults: {}, mapping_presets: {}, strict: false) @name = name.to_sym @styles = styles @mapping_presets = mapping_presets @strict = !!strict @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.
79 80 81 82 83 84 85 86 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 79 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
48 49 50 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 48 def blend(value) @params[:blend] = value.to_sym end |
#evaluate { ... } ⇒ Vizcore::DSL::LayerGroupBuilder
Evaluate a group block.
30 31 32 33 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 30 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.
40 41 42 43 44 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 40 def layer(name, &block) builder = LayerBuilder.new(name: name, styles: @styles, mapping_presets: @mapping_presets, defaults: layer_defaults, strict: @strict) builder.evaluate(&block) @layers << builder.to_h end |
#palette(*colors) ⇒ Array<String>
Store an ordered color palette shared by nested layers.
57 58 59 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 57 def palette(*colors) @params[:palette] = normalize_palette(colors) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
88 89 90 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 88 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.
73 74 75 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 73 def to_a @layers.map { |layer| deep_dup(layer) } end |
#use_style(name) ⇒ Hash
Merge a named style into this group’s shared params.
66 67 68 69 70 |
# File 'lib/vizcore/dsl/layer_group_builder.rb', line 66 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 |