Module: Require

Defined in:
lib/util/util.rb,
lib/require-me.rb

Defined Under Namespace

Modules: Directory

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.base_pathObject

Returns the value of attribute base_path.



6
7
8
# File 'lib/require-me.rb', line 6

def base_path
  @base_path
end

.tracingObject

Returns the value of attribute tracing.



7
8
9
# File 'lib/require-me.rb', line 7

def tracing
  @tracing
end

.verboseObject

Returns the value of attribute verbose.



8
9
10
# File 'lib/require-me.rb', line 8

def verbose
  @verbose
end

Class Method Details

.enter(name, options = {}) {|base_path| ... } ⇒ Object

Yields:



27
28
29
30
31
32
# File 'lib/require-me.rb', line 27

def self.enter(name, options = {}, &block)
  options[:recursive] = true
  file = folder(name, options)
  base_path = File.dirname(file)
  yield base_path    
end

.folder(name, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/require-me.rb', line 35

def self.folder(name, options = {})
  recursive = options[:recursive]
  folder_list = options[:folders]
  file_pattern =  recursive ? "#{name}/**/*.rb" : "#{name}/*.rb" 

  base_dir = File.dirname(__FILE__)

  curr_base_path = options[:base_path] || base_path || base_dir

  # puts "base_path: #{curr_base_path}, base_dir:#{base_dir}, :base_path #{base_path}"

  path = File.join(curr_base_path, file_pattern)
  required_files = []

  puts_trace "folder:: name: #{name}", options    

  if !options[:root_files] || options[:root_files] == :before
    required_files << require_root_files(name, folder_list, path, options)
    # options[:root] = false
    required_files << require_folder_list(name, folder_list, options)    
  else
    required_files << require_folder_list(name, folder_list, options)          
    required_files << require_root_files(name, folder_list, path, options)
    # options[:root] = false      
  end
  required_files.flatten
end

.folders(*names, opt) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/require-me.rb', line 17

def self.folders(*names, opt)
  opt.kind_of?(String) ? options = {} : options = opt 
  required_files = []
  names.each do |path| 
    options[:root] = path if is_root?(path, options) 
    required_files << folder(path, options)
  end
  required_files.flatten
end

.recursive(*names, opt, &block) ⇒ Object



11
12
13
14
15
# File 'lib/require-me.rb', line 11

def self.recursive(*names, opt, &block)
  opt.kind_of?(String) ? options = {} : options = opt 
  options[:recursive] = true
  names.each{|name| folder(name, options) }
end