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
|
# File 'lib/riot-datamapper/has_property.rb', line 6
def evaluate(model, field, *macro_info)
type, options = macro_info
property = model.properties[field]
fail_msg = "expected #{model} to have property :#{field}"
pass_msg = "#{model} has property :#{field}"
type_msg = " with type '#{type}'"
options_msg = " with options #{options.inspect}"
return fail(fail_msg) if property.nil?
if type
if property.class.to_s.include? type
pass_msg << type_msg
else
return fail(fail_msg + type_msg)
end
end
if options
mismatch = options.reject do |key,value|
property.method(key).call == value
end
if mismatch.empty?
pass_msg<<(options_msg)
else
return fail(fail_msg + options_msg)
end
end
pass(pass_msg)
end
|