5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/riot-mongo_mapper/has_key.rb', line 5
def evaluate(model, *key_macro_info)
key_name, key_type, options = key_macro_info
key = model.keys[key_name.to_s]
if key.nil?
fail("expected #{model} to have field #{key_name}")
else
type_valid = (key.type == key_type)
options_valid = options ? options.all? { |field,value| key.options[field] == value } : true
options_valid && type_valid ? pass("#{model} has key '#{key_name}' with options #{options.inspect}") :
fail("expected #{model} to have options #{options.inspect} on key #{key_name}")
end
end
|