Class: LanGrove::Find

Inherits:
Object
  • Object
show all
Defined in:
lib/langrove/ext/find.rb

Class Method Summary collapse

Class Method Details

.find_file(path, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/langrove/ext/find.rb', line 48

def self.find_file( path, &block )
  
  puts "in #{path}"
  
  Dir.entries( path ).each do | sub |
    
    next if sub == '.'
    next if sub == '..'
    
    subdir = "#{path}/#{sub}"
    
    begin
      
      if @incl.nil? then
        
       yield relative(subdir) if block
        
      else
      
        yield relative(subdir) unless /#{@incl}/.match( subdir ).nil?
        
      end
      
      next
      
    end if File.file?( subdir ) and block
    
    find_file( subdir, &block )
    
  end
  
end

.relative(file_path) ⇒ Object



81
82
83
84
85
86
# File 'lib/langrove/ext/find.rb', line 81

def self.relative( file_path )
  
  return file_path.gsub( "#{@path}/",'' ) if @relative
  return file_path
  
end

.with(arg_hash, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/langrove/ext/find.rb', line 5

def self.with( arg_hash , &block )
  
  type = :file
  @path = '.'
  
  #
  # TODO: filter 
  #
  
  @incl = nil
  
  @relative = false
  
  
    arg_hash.each do |key, value|
      
      case key
        
        when :type
        
          type = value
          
        when :path
          
          @path = value
          
        when :include
          
          @incl = value
          
        when :relative
          
          @relative = value
          
      end
 
    
  end
  
  self.send( :"find_#{type}", @path,  &block )
  
end