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
|
# File 'lib/orientdb/oclass.rb', line 9
def add(property_name, type, options = { })
property_name = property_name.to_s
if exists_property(property_name)
puts "We already have that property name [#{property_name}]"
return false
end
type = type.oclass if type.respond_to?(:oclass)
case type
when SchemaType
prop = create_property property_name, type
when Symbol
prop = create_property property_name, type_for(type)
when OClassImpl
prop = create_property property_name, type_for(:link), type
when Array
type, sub_type = type_for(type.first), type_for(type.last)
prop = create_property property_name, type, sub_type
else
raise "ERROR! Unknown type [ #{property_name} | #{type} : #{type.class.name} ]"
end
prop.set_min options[:min].to_s unless options[:min].nil?
prop.set_max options[:max].to_s unless options[:max].nil?
prop.set_mandatory !!options[:mandatory] unless options[:mandatory].nil?
prop.set_not_null options[:not_null] unless options[:not_null].nil?
unless options[:index].nil?
index_type = options[:index] == true ? INDEX_TYPES[:notunique] : INDEX_TYPES[options[:index]]
prop.createIndex index_type
end
self
end
|