Sha256: c8ddfa9ae68a3d29dbb572d83c1e54241d6b3650b1f03f17bccb7f051b457102

Contents?: true

Size: 630 Bytes

Versions: 12

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

class StimulusReflex::Element < OpenStruct
  attr_reader :attributes, :data_attributes

  def initialize(data = {})
    @attributes = HashWithIndifferentAccess.new(data["attrs"] || {})
    @data_attributes = HashWithIndifferentAccess.new(data["dataset"] || {})
    all_attributes = @attributes.merge(@data_attributes)
    super all_attributes.merge(all_attributes.transform_keys(&:underscore))
    @data_attributes.transform_keys! { |key| key.delete_prefix "data-" }
  end

  def dataset
    @dataset ||= OpenStruct.new(data_attributes.merge(data_attributes.transform_keys(&:underscore)))
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
stimulus_reflex-3.3.0 lib/stimulus_reflex/element.rb
stimulus_reflex-3.3.0.pre6 lib/stimulus_reflex/element.rb
stimulus_reflex-3.3.0.pre5 lib/stimulus_reflex/element.rb
stimulus_reflex-3.3.0.pre4 lib/stimulus_reflex/element.rb
stimulus_reflex-3.3.0.pre3 lib/stimulus_reflex/element.rb
stimulus_reflex-3.3.0.pre2 lib/stimulus_reflex/element.rb
stimulus_reflex-3.3.0.pre1 lib/stimulus_reflex/element.rb
stimulus_reflex-3.3.0.pre0 lib/stimulus_reflex/element.rb
stimulus_reflex-3.2.3 lib/stimulus_reflex/element.rb
stimulus_reflex-3.2.2 lib/stimulus_reflex/element.rb
stimulus_reflex-3.2.2.pre1 lib/stimulus_reflex/element.rb
stimulus_reflex-3.2.2.pre0 lib/stimulus_reflex/element.rb