Class: TorqueBox::VFS::GlobFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/vfs/glob_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(child_path, glob, dirs_only) ⇒ GlobFilter

Returns a new instance of GlobFilter.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/torquebox/vfs/glob_filter.rb', line 26

def initialize(child_path, glob, dirs_only)
  regexp_str = GlobTranslator.translate( glob )
  if ( child_path && child_path != '' )
    if ( child_path[-1,1] == '/' )
      regexp_str = "^#{child_path}#{regexp_str}$"
    else
      regexp_str = "^#{child_path}/#{regexp_str}$"
    end
  else
    regexp_str = "^#{regexp_str}$"
  end
  @regexp = Regexp.new( regexp_str )
  @dirs_only = dirs_only
  # puts "glob #{glob} ==> #{@regexp}"
end

Instance Method Details

#accepts(file) ⇒ Object



42
43
44
45
46
# File 'lib/torquebox/vfs/glob_filter.rb', line 42

def accepts(file)
  matched = !!( @regexp =~ file.path_name.to_s )
  matched &&= file.directory? if @dirs_only
  matched
end

#to_sObject



48
49
50
# File 'lib/torquebox/vfs/glob_filter.rb', line 48

def to_s
  "#{@regexp}, dirs_only: #{@dirs_only}"
end