Sha256: 750c848ef501bd6a8e3c83de895da913b71ab4ec22f9ac3f1938aa64100cc14b

Contents?: true

Size: 831 Bytes

Versions: 5

Compression:

Stored size: 831 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 datastore 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

5 entries across 5 versions & 1 rubygems

Version Path
dynamoid-3.6.0 lib/dynamoid/loadable.rb
dynamoid-3.5.0 lib/dynamoid/loadable.rb
dynamoid-3.4.1 lib/dynamoid/loadable.rb
dynamoid-3.4.0 lib/dynamoid/loadable.rb
dynamoid-3.3.0 lib/dynamoid/loadable.rb