Class: StimulusReflex::Element
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- StimulusReflex::Element
- Includes:
- AttributeBuilder
- Defined in:
- lib/stimulus_reflex/element.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#dataset ⇒ Object
(also: #data_attributes)
readonly
Returns the value of attribute dataset.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(data = {}) ⇒ Element
constructor
A new instance of Element.
- #to_dom_id ⇒ Object
Methods included from AttributeBuilder
#build_data_attrs, #build_underscored
Constructor Details
#initialize(data = {}) ⇒ Element
Returns a new instance of Element.
15 16 17 18 19 20 21 |
# File 'lib/stimulus_reflex/element.rb', line 15 def initialize(data = {}) @attrs = HashWithIndifferentAccess.new(data["attrs"] || {}) @dataset = StimulusReflex::Dataset.new(data) all_attributes = @attrs.merge(@dataset.attrs) super build_underscored(all_attributes) end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
9 10 11 |
# File 'lib/stimulus_reflex/element.rb', line 9 def attrs @attrs end |
#dataset ⇒ Object (readonly) Also known as: data_attributes
Returns the value of attribute dataset.
9 10 11 |
# File 'lib/stimulus_reflex/element.rb', line 9 def dataset @dataset end |
Instance Method Details
#attributes ⇒ Object
23 24 25 |
# File 'lib/stimulus_reflex/element.rb', line 23 def attributes @attributes ||= OpenStruct.new(build_underscored(attrs)) end |
#to_dom_id ⇒ Object
27 28 29 30 31 |
# File 'lib/stimulus_reflex/element.rb', line 27 def to_dom_id raise NoIDError.new "The element `morph` is called on must have a valid DOM ID" if id.blank? "##{id}" end |