Class: WorkFlow

Inherits:
Object show all
Extended by:
Assertions::ClassMethods, ClassMethods
Includes:
Assertions, Constants, Examples
Defined in:
app/models/work_flow.rb

Direct Known Subclasses

Release

Defined Under Namespace

Modules: Assertions, ClassMethods, Constants, Examples

Constant Summary collapse

@@cached_unit_versions =
{}

Constants included from Constants

Constants::Branch_compression, Constants::Branch_enhancement

Constants included from Examples

Examples::TestFile, Examples::TestWorkFlow

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions::ClassMethods

assert_post_conditions, assert_pre_conditions

Methods included from ClassMethods

all, merge_range, revison_tag

Methods included from Assertions

#assert_deserving_branch, #assert_post_conditions, #assert_pre_conditions

Constructor Details

#initialize(testable_file, related_files = RelatedFile.new_from_path?(testable_file), repository = Repository.new(related_files.project_root_dir)) ⇒ WorkFlow

Returns a new instance of WorkFlow.


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/work_flow.rb', line 55

def initialize(testable_file, 
	related_files=RelatedFile.new_from_path?(testable_file),
	repository=Repository.new(related_files.project_root_dir))
#	message= "edit_files do not exist\n argv=#{argv.inspect}" 
#	message+= "\n related_files.edit_files=#{related_files.edit_files.inspect}" 
#	message+= "\n related_files.missing_files=#{related_files.missing_files.inspect}" 
#	raise message if  @related_files.edit_files.empty?
	@testable_file=testable_file
	@related_files=related_files
	@repository=repository
	index=Branch_enhancement.index(repository.current_branch_name?)
	if index.nil? then
		@branch_index=-1
	else
		@branch_index=index
	end #if
end

Instance Attribute Details

#edit_filesObject (readonly)

Define related (unit) versions Use as current, lower/upper bound, branch history parametized by related files, repository, branch_number, executable record error_score, recent_test, time


54
55
56
# File 'app/models/work_flow.rb', line 54

def edit_files
  @edit_files
end

Define related (unit) versions Use as current, lower/upper bound, branch history parametized by related files, repository, branch_number, executable record error_score, recent_test, time


54
55
56
# File 'app/models/work_flow.rb', line 54

def related_files
  @related_files
end

#repositoryObject (readonly)

Define related (unit) versions Use as current, lower/upper bound, branch history parametized by related files, repository, branch_number, executable record error_score, recent_test, time


54
55
56
# File 'app/models/work_flow.rb', line 54

def repository
  @repository
end

Instance Method Details

#deserving_branch?(executable = @related_files.model_test_pathname?) ⇒ Boolean

minimal_comparison

Returns:

  • (Boolean)

120
121
122
123
124
125
# File 'app/models/work_flow.rb', line 120

def deserving_branch?(executable=@related_files.model_test_pathname?)
		error_score=@repository.error_score?(executable)
		error_classification=Repository::Error_classification.fetch(error_score, :multiple_tests_fail)
		branch_compression=Branch_compression[error_classification]
		branch_enhancement=Branch_enhancement[branch_compression]
end

#editObject

merge


134
135
136
137
138
139
# File 'app/models/work_flow.rb', line 134

def edit
	command_string="diffuse"+ version_comparison + test_files
	puts command_string if $VERBOSE
	edit=ShellCommands.new(command_string)
	edit.assert_post_conditions
end

#emacs(executable = @related_files.model_test_pathname?) ⇒ Object

minimal_edit


145
146
147
148
149
# File 'app/models/work_flow.rb', line 145

def emacs(executable=@related_files.model_test_pathname?)
	emacs=ShellCommands.new("emacs --no-splash " + @related_files.edit_files.join(' '))
	puts emacs.command_string
	emacs.assert_post_conditions
end

#functional_parallelism(edit_files = @related_files.edit_files) ⇒ Object

goldilocks


90
91
92
93
94
95
96
97
98
99
# File 'app/models/work_flow.rb', line 90

def functional_parallelism(edit_files=@related_files.edit_files)
	[
	[related_files.model_pathname?, related_files.model_test_pathname?],
	[related_files.assertions_pathname?, related_files.model_test_pathname?],
	[related_files.model_test_pathname?, related_files.pathname_pattern?(:integration_test)],
	[related_files.assertions_pathname?, related_files.assertions_test_pathname?]
	].select do |fp|
		fp-edit_files==[] # files must exist to be edited?
	end #map
end

#goldilocks(filename, middle_branch = @repository.current_branch_name?.to_sym) ⇒ Object

version_comparison


81
82
83
84
85
86
87
88
89
# File 'app/models/work_flow.rb', line 81

def goldilocks(filename, middle_branch=@repository.current_branch_name?.to_sym)
	current_index=WorkFlow::Branch_enhancement.index(middle_branch)
	last_slot_index=WorkFlow::Branch_enhancement.size-1
	right_index=[current_index+1, last_slot_index].min
	left_index=right_index-1 
	relative_filename=	Pathname.new(filename).relative_path_from(Pathname.new(Dir.pwd)).to_s

	" -t #{WorkFlow.revison_tag(WorkFlow::Branch_enhancement[left_index])} #{relative_filename} #{relative_filename} #{WorkFlow.revison_tag(WorkFlow::Branch_enhancement[right_index])} #{relative_filename}"
end

#merge(target_branch, source_branch) ⇒ Object

deserving_branch


126
127
128
129
130
131
132
133
# File 'app/models/work_flow.rb', line 126

def merge(target_branch, source_branch)
	@repository.safely_visit_branch(target_branch) do |changes_branch|
		merge_status=@repository.git_command('merge '+source_branch.to_s)
		if !merge_status.success? then
			merge_status=git_command('mergetool')
		end #if
	end #safely_visit_branch
end

#minimal_comparison?Boolean

test_files

Returns:

  • (Boolean)

110
111
112
113
114
115
116
117
118
119
# File 'app/models/work_flow.rb', line 110

def minimal_comparison?
	FilePattern::All.map do |p|
		min_path=Pathname.new(p.pathname_glob('minimal'+@related_files.default_test_class_id?.to_s)).relative_path_from(Pathname.new(Dir.pwd)).to_s
		path=Pathname.new(p.pathname_glob(@related_files.model_basename)).relative_path_from(Pathname.new(Dir.pwd)).to_s
		puts "File.exists?('#{min_path}')==#{File.exists?(min_path)}, File.exists?('#{path}')==#{File.exists?(path)}" if $VERBOSE
		if File.exists?(min_path) && File.exists?(path) then
			' -t '+path+' '+min_path
		end #if
	end.compact.join #map
end

#minimal_editObject

edit


140
141
142
143
144
# File 'app/models/work_flow.rb', line 140

def minimal_edit
	edit=ShellCommands.new("diffuse"+ version_comparison + test_files + minimal_comparison?)
	puts edit.command_string
	edit.assert_post_conditions
end

#test(executable = @related_files.model_test_pathname?) ⇒ Object

emacs


150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/models/work_flow.rb', line 150

def test(executable=@related_files.model_test_pathname?)
	begin
		deserving_branch=deserving_branch?(executable)
		puts deserving_branch if $VERBOSE
		WorkFlow.merge_range(deserving_branch). each do |i|
			@repository.safely_visit_branch(Branch_enhancement[i]) do |changes_branch|
				merge(Branch_enhancement[i], deserving_branch)
				@repository.validate_commit(changes_branch, @related_files.tested_files(executable))
			end #safely_visit_branch
			@repository.recent_test.puts
			edit
		end #each
	end until !@repository.something_to_commit? 
end

#test_files(edit_files = @related_files.edit_files) ⇒ Object

functional_parallelism


100
101
102
103
104
105
106
107
108
109
# File 'app/models/work_flow.rb', line 100

def test_files(edit_files=@related_files.edit_files)
	pairs=functional_parallelism(edit_files).map do |p|

		' -t '+p.map do |f|
			Pathname.new(f).relative_path_from(Pathname.new(Dir.pwd)).to_s
			
		end.join(' ') #map
	end #map
	pairs.join(' ')
end

#unit_test(executable = @related_files.model_test_pathname?) ⇒ Object

test


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'app/models/work_flow.rb', line 164

def unit_test(executable=@related_files.model_test_pathname?)
	begin
		deserving_branch=deserving_branch?(executable)
		if @repository.recent_test.success? then
			break
		end #if
		@repository.recent_test.puts
		puts deserving_branch if $VERBOSE
		@repository.safely_visit_branch(deserving_branch) do |changes_branch|
			@repository.validate_commit(changes_branch, @related_files.tested_files(executable))
		end #safely_visit_branch
		if !@repository.something_to_commit? then
			@repository.confirm_branch_switch(deserving_branch)
		end #if
		edit
	end until !@repository.something_to_commit? 
end

#version_comparison(files = nil) ⇒ Object

initialize


72
73
74
75
76
77
78
79
80
# File 'app/models/work_flow.rb', line 72

def version_comparison(files=nil)
	if files.nil? then
		files=@related_files.edit_files
	end #if
	ret=files.map do |f|
		goldilocks(f)
	end #map
	ret.join(' ')
end