Class: MatchedPathName

Inherits:
Object show all
Includes:
NoDB
Defined in:
app/models/code.rb

Overview

class CodeBase

Constant Summary collapse

FILE_MOD_TIMES =

called by suggest_test_runs for ambiguous (shared)

MatchedPathName.all.map { |pathname_and_spec| { :pathname => pathname_and_spec[:pathname],:mtime => File.mtime(pathname_and_spec[:pathname]), :spec => pathname_and_spec[:spec]}}.sort! {|x,y| y[:mtime] <=> x[:mtime] }

Constants included from NoDB

NoDB::DEFAULT_TYPE

Constants included from ColumnGroup::ClassMethods

ColumnGroup::ClassMethods::History_columns

Constants included from GenericGrep::ClassMethods

GenericGrep::ClassMethods::ASSOCIATION_MACRO_LETTERS, GenericGrep::ClassMethods::ASSOCIATION_MACRO_PATTERN

Constants included from GenericTableAssociation::Examples

GenericTableAssociation::Examples::First_stream_method

Instance Attribute Summary

Attributes included from NoDB

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NoDB

#[], #[]=, #clone, #each_pair, #has_key?, #insert_sql, #keys, #table_class, #table_name

Methods included from Generic_Table::ClassMethods

#is_active_record_method?, #model_file_name, #nesting, #one_pass_statistics, #sample, #sample_burst

Methods included from ColumnGroup::ClassMethods

#attribute_ddl, #attribute_rails_type, #attribute_ruby_type, #candidate_logical_keys_from_indexes, #categorical?, #column_symbols, #default_logical_primary_key, #defaulted_primary_logical_key?, #history_type?, #is_logical_primary_key?, #logical_attributes, #logical_primary_key, #logical_primary_key_recursive, #numerical?, #probably_categorical?, #probably_numerical?, #sequential_id?

Methods included from GenericGrep::ClassMethods

#all_associations, #association_grep, #association_grep_pattern, #association_macro_type, #association_type, #belongs_to_association?, #grep_all_associations_command, #grep_command, #has_many_association?, #has_one_association?, #model_grep, #model_grep_command

Methods included from GenericTableHtml::ClassMethods

#column_order, #header_html, #table_html

Methods included from Generic_Table

activeRecordTableNotCreatedYet?, classDefiniton, classReference, class_of_name, eval_constant, is_ActiveRecord_table?, is_generic_table?, is_generic_table_name?, is_table?, rails_MVC_class?, rubyClassName, table_exists?

Methods included from GenericTableAssociation

#associated_foreign_key_records, #associated_to_s, #association_class, #association_has_data, #association_state, #foreign_key_points_to_me?, #foreign_key_to_association, #foreign_key_value, #logical_primary_key_recursive_value, #logical_primary_key_value, #name_to_association

Methods included from GenericTableAssociation::Assertions::ClassMethods

#assert_foreign_keys_not_nil, #assert_invariant, #assert_post_conditions, #assert_pre_conditions

Methods included from GenericTableAssociation::Assertions

#assert_associated_foreign_key, #assert_associated_foreign_key_name, #assert_association, #assert_association_methods, #assert_association_to_many, #assert_association_to_one, #assert_foreign_key_association_names, #assert_foreign_key_name, #assert_foreign_key_not_nil, #assert_foreign_keys_not_nil, #assert_invariant, #assert_post_conditions, #assert_pre_conditions

Methods included from GenericTableHtml

#column_html, #rails_route, #row_html

Constructor Details

#initialize(pathname, specified_spec = nil) ⇒ MatchedPathName

Returns a new instance of MatchedPathName.


246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'app/models/code.rb', line 246

def initialize(pathname, specified_spec=nil)
	super()
	self[:pathname]=pathname
	self[:mtime] = File.mtime(pathname)
	if specified_spec.nil? then
		CodeBase.all.each do |spec|
			matchData=pathname.match(spec[:Dir_glob])
			if matchData then
				self[:matchData]=matchData # add match data found
				self[:spec]=spec
				return self
			end #if
		end #each
		self[:spec]=nil # not matched
	else
		self[:spec]=specified_spec
	end #if
	self[:matchData]=nil # not matched
end

Class Method Details

.allObject

Returns all matched files. Candidates for new test run (including shared files) Called by all_tests


274
275
276
277
278
279
280
# File 'app/models/code.rb', line 274

def MatchedPathName.all
	CodeBase.all.map  do |spec|
		spec.pathnames.map do |pathname|
			MatchedPathName.new(pathname, spec)
		end #map
	end.flatten.sort! {|x,y| y[:mtime] <=> x[:mtime] } #map
end

.all_tests(test_type) ⇒ Object


283
284
285
286
287
# File 'app/models/code.rb', line 283

def MatchedPathName.all_tests(test_type)
	test_matches= all.select {|match| match[:test_type]=test_type}
	ret=test_matches.map {|m| m.suggest_test_runs}.flatten
	return ret
end

.schedule_testsObject

test_schedule


322
323
324
325
326
327
328
# File 'app/models/code.rb', line 322

def MatchedPathName.schedule_tests
	MatchedPathName.test_schedule.each do |tr|
		if !tr.up_to_date? then #test updated earlier in this iteration
			tr.run
		end #if
	end #each
end

.test_scheduleObject

priorities: most recent modification time first test previously passed short test run time


313
314
315
316
317
318
319
320
321
# File 'app/models/code.rb', line 313

def MatchedPathName.test_schedule
	MatchedPathName.all.suggest_test_runs.each do |candidate| 
		if candidate.instance_of?(Array) then
			ret=candidate.first{|tr| tr.up_to_date?}
		else
			!candidate.up_to_date?
		end #if
	end #
end

Instance Method Details

#assert_has_attributes(obj) ⇒ Object

assert_no_attributes


268
269
270
# File 'app/models/code.rb', line 268

def assert_has_attributes(obj)
	assert_not_equal(0, obj.size)
end

#assert_no_attributes(obj) ⇒ Object

initialize MatchedPathName


265
266
267
# File 'app/models/code.rb', line 265

def assert_no_attributes(obj)
	assert_equal(0, obj.size)
end

#matched_model_nameObject

model name string captured from pathname


330
331
332
# File 'app/models/code.rb', line 330

def matched_model_name
	return model=self[:matchData][1]
end

#matched_model_name_pluralityObject

model name plurality based on which spec was matched


334
335
336
# File 'app/models/code.rb', line 334

def matched_model_name_plurality
	return model=self[:spec][:plural]
end

#model_nameObject

matched_model_name_plurality


337
338
339
# File 'app/models/code.rb', line 337

def model_name
	return model=ModelName.new(self)
end

#suggest_test_runsObject

Returns TestRun or array of TestRuns for ambiguous Suggest test order to run after file modified


290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'app/models/code.rb', line 290

def suggest_test_runs
#	model_name=model
	test_type=self[:spec][:test_type].to_sym
	if self[:matchData].nil? then
		all_tests=MatchedPathName.all_tests(test_type)
	else
	case self[:spec][:test_type].to_sym
	when :unit
			TestRun.new(:unit,model_name[:singular_model_name], model_name[:plural])
	when :controller
		TestRun.new(:controller,model_name[:singular_model_name], model_name[:plural])
	when :both
		[TestRun.new(:unit,model_name[:singular_model_name], model_name[:plural]),
		TestRun.new(:controller,model_name[:singular_model_name], model_name[:plural])]
	else
		raise "bad test_type=#{test_type}"
	end #case
	end #if
end

#test_nameObject

model_name


340
341
342
# File 'app/models/code.rb', line 340

def test_name
	return model=self[:matchData][2]
end