Sha256: 593ed94d0a8e3ee11550f514a15070d7f84c9061964d3a556b5c231d539932bb

Contents?: true

Size: 911 Bytes

Versions: 28

Compression:

Stored size: 911 Bytes

Contents

module Shoulda
  module Matchers
    module ActiveRecord
      # @private
      module Uniqueness
        # @private
        class Model
          def self.next_unique_copy_of(model_name, namespace)
            model = new(model_name, namespace)

            while model.already_exists?
              model = model.next
            end

            model
          end

          def initialize(name, namespace)
            @name = name
            @namespace = namespace
          end

          def already_exists?
            namespace.has?(name)
          end

          def next
            Model.new(name.next, namespace)
          end

          def symlink_to(parent)
            namespace.set(name, parent.dup)
          end

          def to_s
            [namespace, name].join('::')
          end

          protected

          attr_reader :name, :namespace
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
shoulda-matchers-6.1.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-6.0.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-5.3.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-5.2.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-5.1.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-5.0.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-5.0.0.rc1 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.5.1 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.5.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.4.1 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.4.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.3.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.2.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.1.2 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.1.1 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.1.0 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.0.1 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-3.1.3 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-4.0.0.rc1 lib/shoulda/matchers/active_record/uniqueness/model.rb
shoulda-matchers-3.1.2 lib/shoulda/matchers/active_record/uniqueness/model.rb