9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/emf/rgen_ext.rb', line 9
def build(values={})
instance = self.new
if values.is_a? Hash
values.each do |k,v|
attribute = self.ecore.eAllAttributes.find {|x| x.name==k.to_s}
reference = self.ecore.eAllReferences.find {|x| x.name==k.to_s}
raise EMF::UnexistingFeature.new(k.to_s) unless (attribute or reference)
setter = (k.to_s+'=').to_sym
instance.send setter, v
end
else
has_dynamic = false
self.ecore.eAllAttributes.each {|a| has_dynamic|=a.name=='dynamic'}
d = 0
d = 1 if has_dynamic
raise EMF::SingleAttributeRequired.new(self.ecore.name,self.ecore.eAllAttributes) if self.ecore.eAllAttributes.count!=1+d
attribute = self.ecore.eAllAttributes[0]
set_attr(instance,attribute,values)
end
instance
end
|