Class: FilePattern

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Extended by:
Assertions::ClassMethods, ClassMethods
Includes:
Assertions, Constants
Defined in:
app/models/file_pattern.rb

Defined Under Namespace

Modules: Assertions, ClassMethods, Constants, Examples

Constant Summary

Constants included from Constants

Constants::Absolute_directory_regexp, Constants::Absolute_pathname_regexp, Constants::All, Constants::Basename_character_regexp, Constants::Basename_regexp, Constants::Directory_delimiter, Constants::Pathname_character_regexp, Constants::Patterns, Constants::Project_root_directory, Constants::Relative_directory_regexp, Constants::Relative_pathname_regexp

Constants included from Regexp::Constants

Regexp::Constants::Any, Regexp::Constants::Any_binary_char_string, Regexp::Constants::Default_options, Regexp::Constants::End_string, Regexp::Constants::End_string_less_newline, Regexp::Constants::Many, Regexp::Constants::Optional, Regexp::Constants::Start_string

Instance Method Summary collapse

Methods included from Assertions::ClassMethods

assert_invariant, assert_pattern_array, assert_post_conditions, assert_pre_conditions

Methods included from ClassMethods

all, find_by_name, find_from_path, path2model_name?, pathnames?, project_root_dir?

Methods included from Assertions

#assert_invariant, #assert_naming_convention_match, #assert_post_conditions, #assert_pre_conditions

Constructor Details

#initialize(hash) ⇒ FilePattern

Constants


103
104
105
106
# File 'app/models/file_pattern.rb', line 103

def initialize(hash)
	@pattern=hash
	super(hash)
end

Instance Method Details

#parse_pathname_regexpObject

path


127
128
129
# File 'app/models/file_pattern.rb', line 127

def parse_pathname_regexp
	Absolute_directory_regexp.capture(:project_root_directory)*self[:sub_directory]+/[[:word:]]+/.capture(:model_basename)+self[:suffix]
end

#path?(model_basename) ⇒ Boolean

sub_directory_match

Returns:

  • (Boolean)

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

def path?(model_basename)
#	raise "" if [email protected]@project_root_dir.instance_of?(String)
	raise self.inspect if !self.instance_of?(FilePattern)
	raise self.inspect if !self[:sub_directory].instance_of?(String)
	raise "model_basename-#{model_basename.inspect}" if !model_basename.instance_of?(String)
	raise "" if !self[:suffix].instance_of?(String)
	self[:sub_directory]+model_basename.to_s+self[:suffix]
end

#pathname_glob(model_basename = '*') ⇒ Object

parse_pathname_regexp


130
131
132
# File 'app/models/file_pattern.rb', line 130

def pathname_glob(model_basename='*')
	Project_root_directory+self[:sub_directory]+model_basename+self[:suffix]
end

#relative_path?(model_basename) ⇒ Boolean

pathname_glob

Returns:

  • (Boolean)

133
134
135
# File 'app/models/file_pattern.rb', line 133

def relative_path?(model_basename)
	Pathname.new(path?(model_basename)).relative_path_from(Pathname.new(Dir.pwd))
end

#sub_directory_match(path) ⇒ Object

suffix_match


113
114
115
116
117
118
# File 'app/models/file_pattern.rb', line 113

def sub_directory_match(path)
	path=File.expand_path(path)
	sub_directory=File.dirname(path)
	expected_sub_directory=self[:sub_directory][0..-2] # drops trailing /
	sub_directory[-expected_sub_directory.size,expected_sub_directory.size]==expected_sub_directory
end

#suffix_match(path) ⇒ Object

def inspect message=“FilePattern<instance_variables=#FilePattern.instance_variablesinstance_variables.inspect, @self=#FilePattern.selfself.inspect>” end #inspect


110
111
112
# File 'app/models/file_pattern.rb', line 110

def suffix_match(path)
	path[-self[:suffix].size, self[:suffix].size] == self[:suffix]
end