```ruby
module UuidMixin
  extend ActiveSupport::Concern
  included do
    before_validation :set_guid, :on => :create if respond_to?(:before_validation)
    validates :guid,  :uniqueness => true, :presence => true
  end

  def dup
    super.tap { |obj| obj.guid = nil }
  end

  private

  def set_guid
    self.guid ||= SecureRandom.uuid if self.respond_to?(:guid) && self.respond_to?(:guid=)
  end

  def default_name_to_guid
    set_guid
    self.name ||= self.guid if self.respond_to?(:guid) && self.respond_to?(:name) && self.respond_to?(:name=)
  end
end
```

Switch to default_value_for rather than custom logic
user
```ruby
module UuidMixin
  extend ActiveSupport::Concern
  included do
    default_value_for(:guid, :allows_nil => false) { SecureRandom.uuid }
    validates :guid,  :uniqueness => true, :presence => true
  end

  def dup
    super.tap { |obj| obj.guid = SecureRandom.uuid }
  end

  private

  def default_name_to_guid
    self.name ||= self.guid if self.respond_to?(:guid) && self.respond_to?(:name) && self.respond_to?(:name=)
  end
end
```
assistant