Sha256: 20a1766a2ee16751903c5fe8451976e67cc5fb9d4fa0371d8e6dfa277249aef4

Contents?: true

Size: 834 Bytes

Versions: 2

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

module Dynamoid
  module Loadable
    extend ActiveSupport::Concern

    def load(attrs)
      attrs.each do |key, value|
        send("#{key}=", value) if respond_to?("#{key}=")
      end
    end

    # Reload an object from the database -- if you suspect the object has changed in the data store and you need those
    # changes to be reflected immediately, you would call this method. This is a consistent read.
    #
    # @return [Dynamoid::Document] the document this method was called on
    #
    # @since 0.2.0
    def reload
      options = { consistent_read: true }

      if self.class.range_key
        options[:range_key] = range_value
      end

      self.attributes = self.class.find(hash_key, **options).attributes
      @associations.values.each(&:reset)
      self
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynamoid-3.7.1 lib/dynamoid/loadable.rb
dynamoid-3.7.0 lib/dynamoid/loadable.rb