Module: Folder::MagicList

Defined in:
lib/folder/magic_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



3
4
5
# File 'lib/folder/magic_list.rb', line 3

def base_path
  @base_path
end

#rel_pathObject

Returns the value of attribute rel_path.



4
5
6
# File 'lib/folder/magic_list.rb', line 4

def rel_path
  @rel_path
end

Instance Method Details

#do_require(*options) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/folder/magic_list.rb', line 6

def do_require(*options)     
  rel_path = options.shift if options && !options.empty?
  each do |file|                     
    req_file = self.rel_path ? File.join(self.rel_path, file) : file                
    require req_file
  end 
  self
end

#except(*reg_exps) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/folder/magic_list.rb', line 26

def except(*reg_exps) 
  duplicate = self.dup.extend(MagicList)  
  duplicate.each do |file|    
    reg_exps.each {|re| duplicate.delete(file) if file.match(re) }         
  end
  duplicate
end

#matching(*reg_exps) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/folder/magic_list.rb', line 34

def matching(*reg_exps) 
  duplicate = self.dup.extend(MagicList)  
  keep_list = []
  duplicate.each do |file| 
    reg_exps.each do |re|
      re = fix(re) if re.kind_of? String
      keep_list << file if file.match(re)
    end
  end                              
  reject_list = (duplicate - keep_list).flatten
  duplicate.delete_these(reject_list)
end

#show_require(*options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/folder/magic_list.rb', line 15

def show_require(*options)
  each do |f|                                                      
    if options.include? :relative                                 
      file_path = File.join(rel_path, f)
      path = Require::Directory.relative_path(base_path, file_path)
    end
    path = File.join(base_path, f) if !options.include? :relative
    path
  end  
end