Sha256: 5858aa61ac24371dab1275980c99b6edd4d62cc47155a738f6b2da8e06b13b87

Contents?: true

Size: 821 Bytes

Versions: 12

Compression:

Stored size: 821 Bytes

Contents

# frozen_string_literal: true

require "stimulus_reflex/dataset"
require "stimulus_reflex/utils/attribute_builder"

class StimulusReflex::Element < OpenStruct
  include StimulusReflex::AttributeBuilder

  attr_reader :attrs, :dataset

  alias_method :data_attributes, :dataset

  delegate :signed, :unsigned, :numeric, :boolean, :data_attrs, to: :dataset

  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

  def attributes
    @attributes ||= OpenStruct.new(build_underscored(attrs))
  end

  def to_dom_id
    raise NoIDError.new "The element `morph` is called on must have a valid DOM ID" if id.blank?

    "##{id}"
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
stimulus_reflex-3.5.0.rc4 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.rc3 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.rc2 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.rc1 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre10 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre9 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre8 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre7 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre6 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre5 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre4 lib/stimulus_reflex/element.rb
stimulus_reflex-3.5.0.pre3 lib/stimulus_reflex/element.rb