9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/codemodels/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 "UnexistingFeature #{k}" unless (attribute or reference)
setter = (k.to_s+'=').to_sym
instance.send setter, v
end
else
raise "SingleAttributeRequired" if self.ecore.eAllAttributes.count!=1
attribute = self.ecore.eAllAttributes[0]
set_attr(instance,attribute,values)
end
instance
end
|