basepath 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/basepath.rb +22 -4
  3. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -1,10 +1,25 @@
1
1
  require 'pathname'
2
2
 
3
+ module Basepath
4
+ extend self
5
+
6
+ def mine(file = false)
7
+ path_to_first_caller = (s = caller.last) ? s.sub(/:\d+(?::in `.*?')?$/, '') : __FILE__
8
+ path = Pathname.new(path_to_first_caller).realpath
9
+ file ? path : path.dirname
10
+ end
11
+
12
+ # used when settings consts and load_path
13
+ def const_expand!(s)
14
+ (s.sub!(RX_CONSTS, '') ? Object.const_get($1) : ::BASE_PATH).join(s);
15
+ end
16
+ end
17
+
3
18
  lambda do
4
19
  return if Object.const_defined?("BASE_PATH")
5
20
 
6
21
  # find and set base
7
- first_path = (s = caller.last) ? s.sub(/:\d+$/, '') : __FILE__
22
+ first_path = (s = caller.last) ? s.sub(/:\d+(?::in `.*?')?$/, '') : __FILE__
8
23
  cur_path = Pathname.new(first_path).dirname.realpath
9
24
  dot_base = '.base'
10
25
  got_base = lambda { cur_path.join(dot_base).exist? }
@@ -17,11 +32,14 @@ lambda do
17
32
  .inject(Hash.new('')) { |h, (k, s)| h[k.to_sym] = s.strip; h }
18
33
 
19
34
  # set path consts
20
- base_conf[:consts].scan(/([A-Z][A-Z0-9_]*)=(.+)/).each { |k, v| Object.const_set(k, ::BASE_PATH.join(v)) }
35
+ consts = base_conf[:consts].scan(/([A-Z][A-Z0-9_]*)=(.+)/).inject({}) { |h, (k, v)| h[k] = v; h }
36
+ RX_CONSTS = /^(#{consts.keys.map(&Regexp.method(:escape)).join('|')})(?:\/|$)/
37
+ consts.each { |k, v| Object.const_set(k, Basepath.const_expand!(v)) }
21
38
 
22
39
  # set load_paths
23
- load_paths = base_conf[:load_paths].split("\n").map { |s| Dir[::BASE_PATH.join(s).to_s] }.flatten
24
- load_paths = load_paths.select { |s| File.directory? s }
40
+ load_paths = base_conf[:load_paths].split("\n").map { |s|
41
+ Dir[Basepath.const_expand!(s).to_s] }.flatten.select { |s|
42
+ File.directory? s }
25
43
  $LOAD_PATH.unshift(*load_paths)
26
44
 
27
45
  # requires
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basepath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Chassot
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-14 00:00:00 -02:00
12
+ date: 2009-12-30 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency