Sha256: d5acd54d241eac84d92594178a22b801a5acbb4ccfed3370ccb93c761d40f323

Contents?: true

Size: 696 Bytes

Versions: 3

Compression:

Stored size: 696 Bytes

Contents

module ElabsMatchers
  module Helpers
    module Orm
      ##
      #
      # Finds the record from the database and return a new instance for that record.
      #
      # @param [Object] record      An instance of an ORM record
      #
      # Example:
      # reload(post)

      def reload(model)
        model.class.find(model.id)
      end

      ##
      #
      # Saves the record and fetches it from the database and return a new instance for that record.
      #
      # @param [Object] record      An instance of an ORM record
      #
      # Example:
      # save_and_reload(post)

      def save_and_reload(model)
        model.save!
        reload(model)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
elabs_matchers-0.0.3 lib/elabs_matchers/helpers/orm.rb
elabs_matchers-0.0.2 lib/elabs_matchers/helpers/orm.rb
elabs_matchers-0.0.1 lib/elabs_matchers/helpers/orm.rb