pathological 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pathological (0.1.4)
4
+ pathological (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
9
  fakefs (0.4.0)
10
10
  minitest (2.5.1)
11
- rdiscount (1.6.8)
12
11
  rr (1.0.3)
13
12
  scope (0.2.3)
14
13
  minitest
15
- yard (0.7.2)
16
14
 
17
15
  PLATFORMS
18
16
  ruby
@@ -20,7 +18,5 @@ PLATFORMS
20
18
  DEPENDENCIES
21
19
  fakefs
22
20
  pathological!
23
- rdiscount (~> 1.6.8)
24
21
  rr (>= 1.0.3)
25
22
  scope (>= 0.2.3)
26
- yard (~> 0.7.2)
@@ -57,8 +57,8 @@ module Pathological
57
57
  end
58
58
  return nil if directory && !File.directory?(directory)
59
59
  # Find the full, absolute path of this directory, resolving symlinks. If no directory was given, use the
60
- # directory where the executed file resides.
61
- full_path = real_path(directory || $0)
60
+ # directory where the file requiring pathological resides.
61
+ full_path = real_path(directory || requiring_filename)
62
62
  current_path = directory ? full_path : File.dirname(full_path)
63
63
  loop do
64
64
  debug "Searching <#{current_path}> for Pathfile."
@@ -155,6 +155,18 @@ module Pathological
155
155
  @@exclude_root ? paths.reject { |path| File.expand_path(path) == File.expand_path(root) } : paths
156
156
  end
157
157
 
158
+ # Searches the call stack for the file that required pathological.
159
+ # If no file can be found, falls back to the currently executing file ($0).
160
+ # This handles the case where the app was launched by another executable (rake, thin, rackup, etc.)
161
+ #
162
+ # @return [String] name of file requiring pathological, or the currently executing file.
163
+ def self.requiring_filename
164
+ requiring_file = Kernel.caller.find do |stack_line|
165
+ stack_line.include?("top (required)") && !stack_line.include?("pathological.rb")
166
+ end
167
+ requiring_file ? requiring_file.match(/(.+):\d+:in/)[1] : $0 rescue $0
168
+ end
169
+
158
170
  private_class_method :debug, :real_path, :parse_pathfile
159
171
 
160
172
  # Reset options
@@ -1,3 +1,3 @@
1
1
  module Pathological
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -27,7 +27,5 @@ Gem::Specification.new do |s|
27
27
  # Require rr >= 1.0.3 and scope >= 0.2.3 for mutual compatibility.
28
28
  s.add_development_dependency "rr", ">= 1.0.3"
29
29
  s.add_development_dependency "scope", ">= 0.2.3"
30
- s.add_development_dependency "yard", "~> 0.7.2"
31
- s.add_development_dependency "rdiscount", "~> 1.6.8"
32
30
  s.add_development_dependency "fakefs"
33
31
  end
@@ -100,6 +100,41 @@ module Pathological
100
100
  end
101
101
  end
102
102
 
103
+ context "#requiring_filename" do
104
+ setup do
105
+ @full_stacktrace = %Q{
106
+ /Users/test/ruby/gems/1.9.1/gems/pathological-0.2.2.1/lib/pathological/base.rb:61:in `find_pathfile'
107
+ /Users/test/gems/pathological-0.2.2.1/lib/pathological/base.rb:36:in `find_load_paths'
108
+ /Users/test/gems/pathological-0.2.2.1/lib/pathological/base.rb:15:in `add_paths!'
109
+ /Users/test/gems/pathological-0.2.2.1/lib/pathological.rb:3:in `<top (required)>'
110
+ /Users/test/ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
111
+ /Users/test/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
112
+ /Users/test/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
113
+ /Users/test/repos/pathological/test/rackup/app.rb:1:in `<top (required)>'
114
+ /Users/test/.rubies/1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
115
+ }.split("\n")
116
+ @bad_stacktrace = %Q{
117
+ /Users/test/repos/pathological/test/rackup/app.rb !!! `<top (required)>'
118
+ }.split("\n")
119
+ @empty_stacktrace = []
120
+ end
121
+
122
+ should "find root file from a stacktrace" do
123
+ stub(Kernel).caller { @full_stacktrace }
124
+ assert_equal "app.rb", File.basename(Pathological.requiring_filename)
125
+ end
126
+
127
+ should "return executing file from malformed stacktrace" do
128
+ stub(Kernel).caller { @bad_stacktrace }
129
+ assert Pathological.requiring_filename
130
+ end
131
+
132
+ should "return executing file if unable to find root file in stacktrace" do
133
+ stub(Kernel).caller { @empty_stacktrace }
134
+ assert Pathological.requiring_filename
135
+ end
136
+ end
137
+
103
138
  context "loading pathological" do
104
139
  setup do
105
140
  @pathfile_contents = ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathological
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-16 00:00:00.000000000Z
13
+ date: 2011-09-28 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rr
17
- requirement: &70361439567920 !ruby/object:Gem::Requirement
17
+ requirement: &2165564740 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.0.3
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70361439567920
25
+ version_requirements: *2165564740
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: scope
28
- requirement: &70361439567420 !ruby/object:Gem::Requirement
28
+ requirement: &2165564280 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,32 +33,10 @@ dependencies:
33
33
  version: 0.2.3
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70361439567420
37
- - !ruby/object:Gem::Dependency
38
- name: yard
39
- requirement: &70361439566960 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 0.7.2
45
- type: :development
46
- prerelease: false
47
- version_requirements: *70361439566960
48
- - !ruby/object:Gem::Dependency
49
- name: rdiscount
50
- requirement: &70361439566380 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ~>
54
- - !ruby/object:Gem::Version
55
- version: 1.6.8
56
- type: :development
57
- prerelease: false
58
- version_requirements: *70361439566380
36
+ version_requirements: *2165564280
59
37
  - !ruby/object:Gem::Dependency
60
38
  name: fakefs
61
- requirement: &70361439565940 !ruby/object:Gem::Requirement
39
+ requirement: &2165563900 !ruby/object:Gem::Requirement
62
40
  none: false
63
41
  requirements:
64
42
  - - ! '>='
@@ -66,7 +44,7 @@ dependencies:
66
44
  version: '0'
67
45
  type: :development
68
46
  prerelease: false
69
- version_requirements: *70361439565940
47
+ version_requirements: *2165563900
70
48
  description: ! " Pathological provides a way to manage a project's require paths
71
49
  by using a small config file that\n indicates all directories to include in the
72
50
  load path.\n"
@@ -77,7 +55,6 @@ executables: []
77
55
  extensions: []
78
56
  extra_rdoc_files: []
79
57
  files:
80
- - .rvmrc
81
58
  - .yardopts
82
59
  - Gemfile
83
60
  - Gemfile.lock
data/.rvmrc DELETED
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # WARNING: DO NOT MANUALLY EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING.
4
- # This file was generated automatically using ofe/tools/rvmrc_create.sh (which is in turn a wrapper around the
5
- # rvm command rvm --rvmrc). It was generated in the following way:
6
- #
7
- # $ rvmrc_create.sh use 1.9.2@pathological --create
8
- #
9
- # Please use rvmrc_create.sh if you want to change what this project rvmrc does.
10
-
11
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
12
- # development environment upon cd'ing into the directory
13
-
14
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
15
- environment_id="ruby-1.9.2-p180@pathological"
16
-
17
- #
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficicent compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- #
23
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
24
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
-
27
- [[ -s ".rvm/hooks/after_use" ]] && . ".rvm/hooks/after_use"
28
- else
29
- # If the environment file has not yet been created, use the RVM CLI to select.
30
- rvm --create use "$environment_id"
31
- fi
32
-
33
- #
34
- # If you use an RVM gemset file to install a list of gems (*.gems), you can have
35
- # it be automatically loaded. Uncomment the following and adjust the filename if
36
- # necessary.
37
- #
38
- # filename=".gems"
39
- # if [[ -s "$filename" ]] ; then
40
- # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
41
- # fi
42
-
43
- #
44
- # If you use bundler and would like to run bundle each time you enter the
45
- # directory, you can uncomment the following code.
46
- #
47
- # # Ensure that Bundler is installed. Install it if it is not.
48
- # if ! command -v bundle >/dev/null; then
49
- # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
50
- # gem install bundler
51
- # fi
52
- #
53
- # # Bundle while reducing excess noise.
54
- # printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
55
- # bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
56
- #
57
-