Class: ViewComponents::ComponentsBuilder::Component
- Inherits:
-
Object
- Object
- ViewComponents::ComponentsBuilder::Component
- Defined in:
- lib/view_components/components_builder.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(context, attributes) ⇒ Component
constructor
A new instance of Component.
- #to_h ⇒ Object
Constructor Details
#initialize(context, attributes) ⇒ Component
Returns a new instance of Component.
8 9 10 11 12 |
# File 'lib/view_components/components_builder.rb', line 8 def initialize(context, attributes) @context = context @attributes = attributes @data = Hash.new end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/view_components/components_builder.rb', line 5 def attributes @attributes end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/view_components/components_builder.rb', line 5 def context @context end |
Class Method Details
.create!(name, sections, attributes) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/view_components/components_builder.rb', line 18 def self.create!(name, sections, attributes) (self.classes ||= {})[name] = Class.new(self) do sections.each do |section| define_method section do |*args, &block| instance_variable_get("@data")[section] = context.capture(&block) end end end end |
Instance Method Details
#to_h ⇒ Object
14 15 16 |
# File 'lib/view_components/components_builder.rb', line 14 def to_h @attributes.merge(@data) end |