Class: Vizcore::DSL::StyleBuilder
- Inherits:
-
Object
- Object
- Vizcore::DSL::StyleBuilder
- Defined in:
- lib/vizcore/dsl/style_builder.rb
Overview
Collects reusable layer parameter presets for the ‘style` DSL.
Instance Method Summary collapse
-
#evaluate { ... } ⇒ Vizcore::DSL::StyleBuilder
Evaluate a style block.
-
#initialize(name:, kind: "style") ⇒ StyleBuilder
constructor
A new instance of StyleBuilder.
-
#method_missing(method_name, *args, &block) ⇒ Object
private
Stores one-argument style setters into ‘params`.
-
#palette(*colors) ⇒ Array<String>
Store an ordered color palette for styles and themes.
- #respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean
-
#to_h ⇒ Hash
Serialized style payload.
Constructor Details
#initialize(name:, kind: "style") ⇒ StyleBuilder
Returns a new instance of StyleBuilder.
9 10 11 12 13 |
# File 'lib/vizcore/dsl/style_builder.rb', line 9 def initialize(name:, kind: "style") @name = name.to_sym @kind = kind @params = {} 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 one-argument style setters into ‘params`.
45 46 47 48 49 50 51 52 |
# File 'lib/vizcore/dsl/style_builder.rb', line 45 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
#evaluate { ... } ⇒ Vizcore::DSL::StyleBuilder
Evaluate a style block.
19 20 21 22 23 24 |
# File 'lib/vizcore/dsl/style_builder.rb', line 19 def evaluate(&block) instance_eval(&block) if block raise ArgumentError, "#{@kind} #{@name} requires at least one parameter" if @params.empty? self end |
#palette(*colors) ⇒ Array<String>
Store an ordered color palette for styles and themes.
39 40 41 |
# File 'lib/vizcore/dsl/style_builder.rb', line 39 def palette(*colors) @params[:palette] = normalize_palette(colors) end |
#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean
54 55 56 |
# File 'lib/vizcore/dsl/style_builder.rb', line 54 def respond_to_missing?(_method_name, _include_private = false) true end |
#to_h ⇒ Hash
Returns serialized style payload.
27 28 29 30 31 32 |
# File 'lib/vizcore/dsl/style_builder.rb', line 27 def to_h { name: @name, params: @params.dup } end |