Class: RelatedFile

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

Defined Under Namespace

Modules: Assertions, ClassMethods, Constants, Examples

Constant Summary

Constants included from Examples

Examples::SELF, Examples::UnboundedFixnumRelatedFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions::ClassMethods

assert_invariant, assert_post_conditions, assert_pre_conditions

Methods included from ClassMethods

new_from_path?

Methods included from Assertions

#assert_default_test_class_id, #assert_invariant, #assert_post_conditions, #assert_pre_conditions, #assert_tested_files

Constructor Details

#initialize(model_class_name = FilePattern.path2model_name?, project_root_dir = FilePattern.project_root_dir?) ⇒ RelatedFile

Returns a new instance of RelatedFile.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/related_file.rb', line 21

def initialize(model_class_name=FilePattern.path2model_name?, project_root_dir=FilePattern.project_root_dir?)
	message="model_class is nil\n$0=#{$0}\n model_class_name=#{model_class_name}\nFile.expand_path=File.expand_path(#{File.expand_path($0)}"
	raise message if model_class_name.nil?
	@model_class_name=model_class_name.to_sym
	if project_root_dir.nil? then
		@project_root_dir='' #empty string not nil
	else
		@project_root_dir= project_root_dir  #not nil
	end #
	@model_basename=@model_class_name.to_s.tableize.singularize
	raise "@model_basename" if @model_basename.nil?
	@edit_files, @missing_files=pathnames?.partition do |p|
		File.exists?(p)
	end #partition
end

Instance Attribute Details

#edit_filesObject (readonly)

Returns the value of attribute edit_files


20
21
22
# File 'app/models/related_file.rb', line 20

def edit_files
  @edit_files
end

#missing_filesObject (readonly)

Returns the value of attribute missing_files


20
21
22
# File 'app/models/related_file.rb', line 20

def missing_files
  @missing_files
end

#model_basenameObject (readonly)

Returns the value of attribute model_basename


20
21
22
# File 'app/models/related_file.rb', line 20

def model_basename
  @model_basename
end

#model_class_nameObject (readonly)

Returns the value of attribute model_class_name


20
21
22
# File 'app/models/related_file.rb', line 20

def model_class_name
  @model_class_name
end

#project_root_dirObject (readonly)

Returns the value of attribute project_root_dir


20
21
22
# File 'app/models/related_file.rb', line 20

def project_root_dir
  @project_root_dir
end

Instance Method Details

#==(other) ⇒ Object

Equality of defining content


37
38
39
40
41
42
43
# File 'app/models/related_file.rb', line 37

def ==(other)
	if model_class_name==other.model_class_name && project_root_dir==other.project_root_dir then
		true
	else
		false
	end #if
end

#assertions_pathname?Boolean

model_test_pathname?

Returns:

  • (Boolean)

57
58
59
# File 'app/models/related_file.rb', line 57

def assertions_pathname?
	pathname_pattern?(:assertions)
end

#assertions_test_pathname?Boolean

assertions_pathname?

Returns:

  • (Boolean)

60
61
62
# File 'app/models/related_file.rb', line 60

def assertions_test_pathname?
	pathname_pattern?(:assertions_test)
end

#data_sources_directory?Boolean

assertions_test_pathname?

Returns:

  • (Boolean)

63
64
65
# File 'app/models/related_file.rb', line 63

def data_sources_directory?
	@project_root_dir+'test/data_sources/'
end

#default_test_class_id?Boolean

pathnames

Returns:

  • (Boolean)

75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/related_file.rb', line 75

def default_test_class_id?
	if File.exists?(self.assertions_test_pathname?) then
		4
	elsif File.exists?(self.assertions_pathname?) then
		3
	elsif File.exists?(self.model_pathname?) then
		2
	elsif File.exists?(self.model_test_pathname?) then
		1
	else
		0 # fewest assumptions, no files
	end #if
end

#default_tests_module_name?Boolean

default_test_class_id

Returns:

  • (Boolean)

88
89
90
# File 'app/models/related_file.rb', line 88

def default_tests_module_name?
	"DefaultTests"+default_test_class_id?.to_s
end

#model_class?Boolean

tested_files

Returns:

  • (Boolean)

106
107
108
# File 'app/models/related_file.rb', line 106

def model_class?
	eval(@model_class_name.to_s)
end

#model_name?Boolean

model_class

Returns:

  • (Boolean)

109
110
111
# File 'app/models/related_file.rb', line 109

def model_name?
	@model_class_name
end

#model_pathname?Boolean

pathname_pattern

Returns:

  • (Boolean)

51
52
53
# File 'app/models/related_file.rb', line 51

def model_pathname?
	pathname_pattern?(:model)
end

#model_test_pathname?Boolean

model_pathname?

Returns:

  • (Boolean)

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

def model_test_pathname?
	pathname_pattern?(:test)
end

#pathname_pattern?(file_spec) ⇒ Boolean

Returns:

  • (Boolean)

44
45
46
47
48
49
50
# File 'app/models/related_file.rb', line 44

def pathname_pattern?(file_spec)
	raise "project_root_dir" if @project_root_dir.nil?
	raise "FilePattern.find_by_name(file_spec)[:sub_directory]" if FilePattern.find_by_name(file_spec)[:sub_directory].nil?
	raise "@model_basename" if @model_basename.nil?
	raise "FilePattern.find_by_name(file_spec)[:suffix]" if FilePattern.find_by_name(file_spec)[:suffix].nil?
	@project_root_dir+FilePattern.find_by_name(file_spec)[:sub_directory]+@model_basename.to_s+FilePattern.find_by_name(file_spec)[:suffix]
end

#pathnames?Boolean

Initially the number of files for the model

Returns:

  • (Boolean)

67
68
69
70
71
72
73
74
# File 'app/models/related_file.rb', line 67

def pathnames?
#	[assertions_test_pathname?, assertions_pathname?, model_test_pathname?, model_pathname?]
	raise "project_root_dir" if @project_root_dir.nil?
	raise "@model_basename" if @model_basename.nil?
	FilePattern::All.map do |p|
		pathname_pattern?(p[:name])
	end #
end

#test_case_class_name?Boolean

default_tests_module?

Returns:

  • (Boolean)

91
92
93
# File 'app/models/related_file.rb', line 91

def test_case_class_name?
	"DefaultTestCase"+default_test_class_id?.to_s
end

#tested_files(executable) ⇒ Object

test_case_class?


94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/related_file.rb', line 94

def tested_files(executable)
	if executable==pathname_pattern?(:script) then # script only
		[model_pathname?, executable]
	else case default_test_class_id? # test files
	when 0 then [model_test_pathname?]
	when 1 then [model_test_pathname?]
	when 2 then [model_pathname?, executable]
	when 3 then [model_pathname?, model_test_pathname?, assertions_pathname?]
	when 4 then [model_pathname?, model_test_pathname?, assertions_pathname?, assertions_test_pathname?]
	end #case
	end-@missing_files #if
end