Module: Loader
- Defined in:
- lib/loader.rb,
lib/loader/meta.rb
Defined Under Namespace
Modules: AutoLoad, Helpers, ObjectExtension
Class Method Summary collapse
- .caller_file(skip = 0) ⇒ Object
- .caller_folder(skip = 0) ⇒ Object
-
.caller_root(*args) ⇒ Object
(also: caller_root_folder)
you can give optional file names that will be searched for.
Class Method Details
.caller_file(skip = 0) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/loader/meta.rb', line 5 def caller_file(skip=0) raise unless skip.class <= Integer skip += 1 return nil if caller[skip].nil? caller_file = caller[skip].scan(/^(.*)(:\d+:\w+)/)[0][0] if caller_file[0] != File::Separator caller_file= File. caller_file end return caller_file end |
.caller_folder(skip = 0) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/loader/meta.rb', line 21 def caller_folder skip= 0 raise unless skip.class <= Integer caller_file_path= caller_file(skip+1) return nil if caller_file_path.nil? if !File.directory?(caller_file_path) caller_file_path= caller_file_path.split(File::Separator) caller_file_path.pop caller_file_path= caller_file_path.join(File::Separator) end return caller_file_path end |
.caller_root(*args) ⇒ Object Also known as: caller_root_folder
you can give optional file names that will be searched for
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/loader/meta.rb', line 40 def caller_root(*args) what_can_be_in_the_root= %w[ gemfile Gemfile GemFile rakefile Rakefile RakeFile config.ru README.md LICENSE LICENSE.txt .gitignore ] + args.map{|e|e.to_s} folder_path= caller_folder(1).split(File::Separator) loop do Dir.glob(File.join(folder_path.join(File::Separator),"*")).map do |element| if !File.directory?(element) if what_can_be_in_the_root.include? element.split(File::Separator).last return folder_path.join(File::Separator) end else if %W[ .git .bundler ].include? element.split(File::Separator).last return folder_path.join(File::Separator) end end end if folder_path.count == 0 return nil else folder_path.pop end end end |