/
attribute.rb
56 lines (44 loc) · 1.16 KB
/
attribute.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
46
47
48
49
50
51
52
53
54
55
56
module FactoryGirl
# Raised when defining an invalid attribute:
# * Defining an attribute which has a name ending in "="
# * Defining an attribute with both a static and lazy value
# * Defining an attribute twice in the same factory
class AttributeDefinitionError < RuntimeError
end
class Attribute #:nodoc:
include Comparable
attr_reader :name, :ignored
def initialize(name, ignored)
@name = name.to_sym
@ignored = ignored
ensure_non_attribute_writer!
end
def add_to(proxy)
end
def association?
false
end
def priority
1
end
def aliases_for?(attr)
FactoryGirl.aliases_for(attr).include?(name)
end
def <=>(another)
return nil unless another.is_a? Attribute
self.priority <=> another.priority
end
def ==(another)
self.object_id == another.object_id
end
private
def ensure_non_attribute_writer!
if @name.to_s =~ /=$/
attribute_name = $`
raise AttributeDefinitionError,
"factory_girl uses 'f.#{attribute_name} value' syntax " +
"rather than 'f.#{attribute_name} = value'"
end
end
end
end