Sha256: a4556ff2f95692303b87774f48fafb1ff6cf32b678659253e62bdee1fb1a300a

Contents?: true

Size: 593 Bytes

Versions: 60

Compression:

Stored size: 593 Bytes

Contents

# frozen_string_literal: true

class LHS::Record

  module AttributeAssignment
    extend ActiveSupport::Concern

    def assign_attributes(new_attributes)
      if !new_attributes.respond_to?(:stringify_keys)
        raise ArgumentError, "When assigning attributes, you must pass a hash as an argument, #{new_attributes.class} passed."
      end
      return if new_attributes.empty?

      _assign_attributes(new_attributes)
    end

    private

    def _assign_attributes(attributes)
      attributes.each do |key, value|
        public_send(:"#{key}=", value)
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
lhs-26.2.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-26.1.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-26.0.1 lib/lhs/concerns/record/attribute_assignment.rb
lhs-26.0.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-25.2.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-25.1.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-25.0.4 lib/lhs/concerns/record/attribute_assignment.rb
lhs-25.0.3 lib/lhs/concerns/record/attribute_assignment.rb
lhs-25.0.2 lib/lhs/concerns/record/attribute_assignment.rb
lhs-25.0.1 lib/lhs/concerns/record/attribute_assignment.rb
lhs-25.0.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-24.1.2 lib/lhs/concerns/record/attribute_assignment.rb
lhs-24.1.1 lib/lhs/concerns/record/attribute_assignment.rb
lhs-24.1.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-24.1.0.pre.2 lib/lhs/concerns/record/attribute_assignment.rb
lhs-24.1.0.pre.1 lib/lhs/concerns/record/attribute_assignment.rb
lhs-24.0.0 lib/lhs/concerns/record/attribute_assignment.rb
lhs-23.0.2 lib/lhs/concerns/record/attribute_assignment.rb
lhs-23.0.1 lib/lhs/concerns/record/attribute_assignment.rb
lhs-23.0.0 lib/lhs/concerns/record/attribute_assignment.rb