Module: RGen::MetamodelBuilder::MMBase::SingletonAddOn

Included in:
RGen::MetamodelBuilder::MMBase
Defined in:
lib/codemodels/rgen_ext.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



81
82
83
# File 'lib/codemodels/rgen_ext.rb', line 81

def ==(other)
	eql? other
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/codemodels/rgen_ext.rb', line 50

def eql?(other)
	# it should ignore relations which has as opposite a containement
	return false unless self.shallow_eql?(other)
	self.class.ecore.eAllReferences.each do |ref|
		self_value = self.get(ref)
		other_value = other.get(ref)
		to_ignore = ref.getEOpposite and ref.getEOpposite.containment
		unless to_ignore
			if ref.containment
				return false unless self_value == other_value
			else
				if (self_value.is_a? Array) or (other_value.is_a? Array)
					return false unless self_value.count==other_value.count
					for i in 0..(self_value.count-1)
						unless self_value[i].shallow_eql?(other_value[i])
							return false 
						end
					end
				else  
					if self_value==nil
						return false unless other_value==nil
					else
						return false unless self_value.shallow_eql?(other_value)
					end
				end
			end
		end						
	end
	true
end

#features_by_name(name) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/codemodels/rgen_ext.rb', line 90

def features_by_name(name)
	features = []
	ecore = self.class.ecore
	ecore.eAllAttributes.select {|a| a.name==name}.each do |a|
		features << a
	end			
	ecore.eAllReferences.select {|r| r.name==name}.each do |r|
		features << r
	end
	features
end

#get(attr_or_ref) ⇒ Object



85
86
87
88
# File 'lib/codemodels/rgen_ext.rb', line 85

def get(attr_or_ref)
	getter = (attr_or_ref.name).to_sym
	send getter
end

#shallow_eql?(other) ⇒ Boolean

It does not check references, it is needed to avoid infinite recursion

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/codemodels/rgen_ext.rb', line 38

def shallow_eql?(other)
	return false if other==nil
	return false unless self.class==other.class
	self.class.ecore.eAllAttributes.each do |attrib|
		raise "Attrib <nil> for class #{self.class.ecore.name}" unless attrib
		self_value  = self.get(attrib)
		other_value = other.get(attrib)
		return false unless self_value == other_value
	end
	true
end