Class: MergeAssociations

Inherits:
Merge
  • Object
show all
Defined in:
lib/xmimerge/merge_associations.rb

Instance Method Summary collapse

Methods inherited from Merge

#check, #check_change_propertie, #merge

Constructor Details

#initialize(from_class, to_class) ⇒ MergeAssociations

Returns a new instance of MergeAssociations.



11
12
13
14
15
# File 'lib/xmimerge/merge_associations.rb', line 11

def initialize(from_class, to_class)
	super()
	@from_class = from_class
	@to_class = to_class
end

Instance Method Details

#check_changes(from_association) ⇒ Object

Parameters:

  • from_association. (Association, #read)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/xmimerge/merge_associations.rb', line 27

def check_changes(from_association)

	@log.debug("Checking association: #{from_association.full_name}")

	# Localiza a associação no modelo destino
	to_association = @to_class.xml_root.association_by_id(from_association.id)

	if to_association.nil?
		# Se não encontrou é poque é um nova associação
		new_association from_association
	else
		# Associação já existe, verifica se houve alterações
		check_existing_association(from_association, to_association)
	end
end

#check_existing_association(from_association, to_association) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/xmimerge/merge_associations.rb', line 84

def check_existing_association(from_association, to_association)

	# Visibility
	check_change_propertie("name", from_association, to_association, "AssociationName")

	# Stereotypes		
	merge = MergeStereotypes.new("Association", from_association, to_association)
	@only_check ? merge.check : merge.merge

	# TaggedValues
	t = MergeTaggedValues.new("Association", from_association, to_association)
	@only_check ? t.check : t.merge


	if from_association.end_a != to_association.end_a
		command = "\t* AssociationEndA #{from_association.end_a.name} {'#{from_association.end_a.participant.full_name}' --> '#{to_association.end_a.participant.full_name}'}"
		@commands.add_command_to_buffer(command)			
	end

	if from_association.end_b != to_association.end_b
		command = "\t* AssociationEndB #{from_association.end_b.name} {'#{from_association.end_b.participant.full_name}' --> '#{to_association.end_b.participant.full_name}'}"
		@commands.add_command_to_buffer(command)				
	end

	# AssociationEnd
	end_a = MergeAssociationEnd.new("AssociationEndA", from_association.end_a, to_association.end_a)
	@only_check ? end_a.check : end_a.merge
	
	end_b = MergeAssociationEnd.new("AssociationEndB", from_association.end_b, to_association.end_b)
	@only_check ? end_b.check : end_b.merge	
end

#check_removedObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/xmimerge/merge_associations.rb', line 43

def check_removed
	@to_class.xml_root.associations.each do |to_association|
		
		ok = false
		@from_class.xml_root.associations.each do |from_association|

			if from_association == to_association
				ok = true
				break
			end
		end
		if !ok
			command = "\t- Association #{to_association.full_name}"
			@commands.add_command_to_buffer(command)
			unless @only_check 
				if @commands.has_command?(command)
					@log.info "[OK] #{command}"
				else
					#@log.info "[NOT] #{command}"
				end
			end
		end
	end		
end

#new_association(from_association) ⇒ Object

Parameters:

  • from_association. (Association, #read)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/xmimerge/merge_associations.rb', line 69

def new_association(from_association)
	@log.debug("New Attribute")		

	command = "\t+ Association #{from_association.full_name}"
	@commands.add_command_to_buffer(command)

	unless @only_check 
		if @commands.has_command?(command)
			@log.info "[OK] #{command}"
		else
			@log.info "[NOT] #{command}"
		end
	end
end

#verifyObject



17
18
19
20
21
22
23
24
# File 'lib/xmimerge/merge_associations.rb', line 17

def verify

	@from_class.associations.each do |from_association|		
		#check_changes(from_association)
	end

	#check_removed
end