Class: Tailmix::Definition::ContextBuilder
- Inherits:
-
Object
- Object
- Tailmix::Definition::ContextBuilder
- Defined in:
- lib/tailmix/definition/context_builder.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#component_name ⇒ Object
readonly
Returns the value of attribute component_name.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #action(name, &block) ⇒ Object
- #build_definition ⇒ Object
- #element(name, classes = "", &block) ⇒ Object
-
#initialize(component_name:) ⇒ ContextBuilder
constructor
A new instance of ContextBuilder.
Constructor Details
#initialize(component_name:) ⇒ ContextBuilder
Returns a new instance of ContextBuilder.
13 14 15 16 17 |
# File 'lib/tailmix/definition/context_builder.rb', line 13 def initialize(component_name:) @elements = {} @actions = {} @component_name = component_name end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
11 12 13 |
# File 'lib/tailmix/definition/context_builder.rb', line 11 def actions @actions end |
#component_name ⇒ Object (readonly)
Returns the value of attribute component_name.
11 12 13 |
# File 'lib/tailmix/definition/context_builder.rb', line 11 def component_name @component_name end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
11 12 13 |
# File 'lib/tailmix/definition/context_builder.rb', line 11 def elements @elements end |
Instance Method Details
#action(name, &block) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/tailmix/definition/context_builder.rb', line 29 def action(name, &block) builder = Builders::ActionBuilder.new proxy = Builders::PayloadProxy.new builder.instance_exec(proxy, &block) @actions[name.to_sym] = builder end |
#build_definition ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/tailmix/definition/context_builder.rb', line 36 def build_definition Definition::Result::Context.new( name: component_name, elements: @elements.transform_values(&:build_definition).freeze, actions: @actions.transform_values(&:build_definition).freeze, ) end |
#element(name, classes = "", &block) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/tailmix/definition/context_builder.rb', line 19 def element(name, classes = "", &block) builder = Builders::ElementBuilder.new(name) builder.attributes.classes(classes.split) builder.instance_eval(&block) if block @elements[name.to_sym] = builder @actions.merge!(builder.auto_actions) end |