/
model.rb
45 lines (36 loc) · 894 Bytes
/
model.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Shoulda
module Matchers
module ActiveRecord
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