Sha256: 4b8daccd7c46e760c95cf5d15345e57d988ea1b499f4f0683f90ccecd888bb5a

Contents?: true

Size: 596 Bytes

Versions: 12

Compression:

Stored size: 596 Bytes

Contents

# frozen_string_literal: true

class DHS::Record

  module AttributeAssignment
    extend ActiveSupport::Concern

    def assign_attributes(new_attributes)
      unless 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

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.5.0 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.4.2 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.4.1 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.4.0 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.3.0 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.2.0 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.1.0 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.0.3 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.0.2 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.0.1 lib/dhs/concerns/record/attribute_assignment.rb
dhs-1.0.0 lib/dhs/concerns/record/attribute_assignment.rb