diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2011-12-23 08:33:21 -0800 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2011-12-23 08:36:44 -0800 |
commit | ac2d6f1898a5aa1aad7cc254290ec9341d2cdf60 (patch) | |
tree | 9a7a912105879ad19b4012a4512aa7598d6bb15a | |
parent | 3d80f03434ba20544a410c13228738f4362d731b (diff) | |
download | coderay-ac2d6f1898a5aa1aad7cc254290ec9341d2cdf60.tar.gz |
Remove assumption about a stable $:
In some environments (e.g. [1]) $: can change between loading the
library and using it.
To avoid this problem, we always pass an absolute path to autoload
internal modules.
[1] https://github.com/pry/pry/issues/280
-rw-r--r-- | lib/coderay.rb | 13 | ||||
-rw-r--r-- | lib/coderay/encoders/html.rb | 6 | ||||
-rw-r--r-- | lib/coderay/scanner.rb | 2 | ||||
-rw-r--r-- | lib/coderay/scanners/java.rb | 2 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 4 |
5 files changed, 19 insertions, 8 deletions
diff --git a/lib/coderay.rb b/lib/coderay.rb index c897220..63ec555 100644 --- a/lib/coderay.rb +++ b/lib/coderay.rb @@ -127,7 +127,18 @@ module CodeRay $CODERAY_DEBUG ||= false - require 'coderay/version' + # Assuming the rel_path is a subpath of lib/ + def self.abs_path(rel_path) + File.join(File.dirname(__FILE__), rel_path) + end + + # In order to work in environments that alter $:, we need to + # set the absolute path when autoloading files. + def self.autoload(const_name, rel_path) + super const_name, abs_path(rel_path) + end + + require abs_path('coderay/version') # helpers autoload :FileType, 'coderay/helpers/file_type' diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 60dfad1..c5d680c 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -109,9 +109,9 @@ module Encoders :hint => false, } - autoload :Output, 'coderay/encoders/html/output' - autoload :CSS, 'coderay/encoders/html/css' - autoload :Numbering, 'coderay/encoders/html/numbering' + autoload :Output, CodeRay.abs_path('coderay/encoders/html/output') + autoload :CSS, CodeRay.abs_path('coderay/encoders/html/css') + autoload :Numbering, CodeRay.abs_path('coderay/encoders/html/numbering') attr_reader :css diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index 7ecbe4f..f102163 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -320,4 +320,4 @@ surrounding code: end end -end
\ No newline at end of file +end diff --git a/lib/coderay/scanners/java.rb b/lib/coderay/scanners/java.rb index d3502e3..50c82c2 100644 --- a/lib/coderay/scanners/java.rb +++ b/lib/coderay/scanners/java.rb @@ -6,7 +6,7 @@ module Scanners register_for :java - autoload :BuiltinTypes, 'coderay/scanners/java/builtin_types' + autoload :BuiltinTypes, CodeRay.abs_path('coderay/scanners/java/builtin_types') # http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html KEYWORDS = %w[ diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 4244ab7..e2e3d1b 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -13,8 +13,8 @@ module Scanners register_for :ruby file_extension 'rb' - autoload :Patterns, 'coderay/scanners/ruby/patterns' - autoload :StringState, 'coderay/scanners/ruby/string_state' + autoload :Patterns, CodeRay.abs_path('coderay/scanners/ruby/patterns') + autoload :StringState, CodeRay.abs_path('coderay/scanners/ruby/string_state') def interpreted_string_state StringState.new :string, true, '"' |