Sha256: 3e929dc20c0c615eb1191c69f1ba226221ed15b736ce8cc0d660107a18005b93
Contents?: true
Size: 747 Bytes
Versions: 58
Compression:
Stored size: 747 Bytes
Contents
# frozen_string_literal: true # Sequel analog for `ActiveRecord::Base#dup` method module Sequel::Plugins::Duplicate module ClassMethods # Returns a copy of current model # # @param model [Sequel::Model] source object # @param new_attrs [Hash] attributes to override # # @return [Sequel::Model] def duplicate(model, **new_attrs) pk = *primary_key attrs = model.values.reject { |key, *| pk.include?(key) } new(**attrs, **new_attrs) end end module InstanceMethods # Returns a copy of current model # # @param new_attrs [Hash] attributes to override # # @return [Sequel::Model] def duplicate(**new_attrs) self.class.duplicate(self, **new_attrs) end end end
Version data entries
58 entries across 58 versions & 1 rubygems