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