Sha256: 555b0cf980c20a13e0f1e41c5e92efc586932f1aac0fb52b1addc4986d6ca920

Contents?: true

Size: 761 Bytes

Versions: 1

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

module Mitake
  module Model
    # @since 0.1.0
    # @api private
    module Attributes
      # @since 0.1.0
      # @api private
      def initialize(attributes = {})
        assign_attributes(attributes)
      end

      # Assign attribute by hash
      #
      # @param attributes [Hash] the attributes to assignment
      #
      # @since 0.1.0
      def assign_attributes(attributes = {})
        attributes.each do |key, value|
          next unless self.class.attribute_names.include?(key.to_s)
          next send("#{key}=", value) if respond_to?("#{key}=")

          type = self.class.attributes[key.to_s]
          instance_variable_set("@#{key}", self.class.cast(value, type))
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mitake-0.1.2 lib/mitake/model/attributes.rb