Guest User

Untitled

a guest
Jun 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. MyProgram
  2.  
  3. MyProgramsrcmyclass.rb
  4.  
  5. MyProgramtestmytest.rb
  6.  
  7. require_relative '../src/myclass'
  8.  
  9. $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "src"))
  10.  
  11. $:.unshift File.expand_path("../../src", __FILE__)
  12. require 'myclass'
  13.  
  14. require File.expand_path "../../src/myclass", __FILE__
  15.  
  16. Pathname(__FILE__).dirname.realpath
  17.  
  18. # Read application config
  19. $hConf, $fConf = {}, File.expand_path("../config.rb", __FILE__)
  20. $hConf = File.open($fConf) {|f| eval(f.read)} if File.exist? $fConf
  21.  
  22. # Application classpath
  23. $: << ($hConf[:appRoot] || File.expand_path("../bin/app", __FILE__))
  24.  
  25. # Ruby libs
  26. $lib = ($hConf[:rubyLib] || File.expand_path("../bin/lib", __FILE__))
  27. ($: << [$lib]).flatten! # lib is string or array, standardize
  28.  
  29. # Site- and server specific config - location of DB, tmp files etc.
  30. {
  31. :webRoot => "/srv/www/myapp/data",
  32. :rubyLib => "/somewhere/lib",
  33. :tmpDir => "/tmp/myapp"
  34. }
  35.  
  36. path='../specific_folder/' # relative path from current file to required folder
  37.  
  38. Dir[File.dirname(__FILE__) + '/'+path+'*.rb'].each do |file|
  39. require_relative path+File.basename(file) # require all files with .rb extension in this folder
  40. end
Add Comment
Please, Sign In to add comment