Module: FilePattern::ClassMethods

Included in:
FilePattern
Defined in:
app/models/file_pattern.rb

Instance Method Summary collapse

Instance Method Details

#allObject


37
38
39
# File 'app/models/file_pattern.rb', line 37

def all
	Constants::All
end

#find_by_name(name) ⇒ Object

project_root_dir


78
79
80
81
82
# File 'app/models/file_pattern.rb', line 78

def find_by_name(name)
	Constants::All.find do |s|
		s[:name]==name
	end #find
end

#find_from_path(path) ⇒ Object

find_by_name


83
84
85
86
87
# File 'app/models/file_pattern.rb', line 83

def find_from_path(path)
	Constants::All.find do |p|
		p.sub_directory_match(path) && p.suffix_match(path)
	end #find
end

#path2model_name?(path = $0) ⇒ Boolean

all

Returns:

  • (Boolean)

40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/file_pattern.rb', line 40

def path2model_name?(path=$0)
	raise "path=#{path.inspect} must be a string" if !path.instance_of?(String)
	path=File.expand_path(path)
	basename=File.basename(path)
	matches=all.map do |s| 
		if s.suffix_match(path) && s.sub_directory_match(path) then
			name_length=basename.size-s[:suffix].size
			basename[0,name_length].camelize.to_sym
		else
			nil
		end #if	
	end #map
	matches.compact.last
end

#pathnames?(model_basename) ⇒ Boolean

pattern_from_path

Returns:

  • (Boolean)

88
89
90
91
92
93
94
# File 'app/models/file_pattern.rb', line 88

def pathnames?(model_basename)
#	raise "project_root_dir" if FilePattern.class_variable_get(:@@project_root_dir).nil?
	raise "model_basename" if model_basename.nil?
	FilePattern::Constants::All.map do |p|
		p.path?(model_basename)
	end #
end

#project_root_dir?(path = $0) ⇒ Boolean

path2model_name

Returns:

  • (Boolean)

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/file_pattern.rb', line 54

def project_root_dir?(path=$0)
	path=File.expand_path(path)
	script_directory_pathname=File.dirname(path)+'/'
	script_directory_name=File.basename(script_directory_pathname)
	ret=case script_directory_name
	when 'unit' then
		File.expand_path(script_directory_pathname+'../../')+'/'
	when 'assertions' then
		File.expand_path(script_directory_pathname+'../../')+'/'
	when 'long_test' then
		File.expand_path(script_directory_pathname+'../../')+'/'
	when 'integration' then
		File.expand_path(script_directory_pathname+'../../')+'/'
	when 'script' then
		File.dirname(script_directory_pathname)+'/'
	when 'models'
		File.expand_path(script_directory_pathname+'../../')+'/'
	else
		warn "can't find test directory. path=#{path.inspect}\n  script_directory_pathname=#{script_directory_pathname.inspect}\n script_directory_name=#{script_directory_name.inspect}"
		script_directory_name+'/'
	end #case
	raise "ret=#{ret} does not end in a slash\npath=#{path}" if ret[-1,1]!= '/'
	return ret
end