From ac2d6f1898a5aa1aad7cc254290ec9341d2cdf60 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 23 Dec 2011 08:33:21 -0800 Subject: 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 --- lib/coderay.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/coderay.rb') 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' -- cgit v1.2.1 From 5c4c0065784c6420224516e13a0c50d86e792363 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Tue, 27 Dec 2011 02:39:02 +0100 Subject: Bug #6: merge ConradIrwin's approach with korny's --- lib/coderay.rb | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'lib/coderay.rb') diff --git a/lib/coderay.rb b/lib/coderay.rb index 63ec555..e54a73b 100644 --- a/lib/coderay.rb +++ b/lib/coderay.rb @@ -127,38 +127,34 @@ module CodeRay $CODERAY_DEBUG ||= false - # 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) + require 'coderay/version' + + CODERAY_PATH = File.join File.dirname(__FILE__), 'coderay' + + # Assuming the path is a subpath of lib/coderay/ + def self.coderay_path *path + File.join CODERAY_PATH, *path end - - require abs_path('coderay/version') # helpers - autoload :FileType, 'coderay/helpers/file_type' + autoload :FileType, coderay_path('helpers', 'file_type') # Tokens - autoload :Tokens, 'coderay/tokens' - autoload :TokensProxy, 'coderay/tokens_proxy' - autoload :TokenKinds, 'coderay/token_kinds' + autoload :Tokens, coderay_path('tokens') + autoload :TokensProxy, coderay_path('tokens_proxy') + autoload :TokenKinds, coderay_path('token_kinds') # Plugin system - autoload :PluginHost, 'coderay/helpers/plugin' - autoload :Plugin, 'coderay/helpers/plugin' + autoload :PluginHost, coderay_path('helpers', 'plugin') + autoload :Plugin, coderay_path('helpers', 'plugin') # Plugins - autoload :Scanners, 'coderay/scanner' - autoload :Encoders, 'coderay/encoder' - autoload :Styles, 'coderay/style' + autoload :Scanners, coderay_path('scanner') + autoload :Encoders, coderay_path('encoder') + autoload :Styles, coderay_path('style') - # Convenience access and reusable Encoder/Scanner pair - autoload :Duo, 'coderay/duo' + # convenience access and reusable Encoder/Scanner pair + autoload :Duo, coderay_path('duo') class << self -- cgit v1.2.1 From c8e21f2e6c83fffcb18e4e1b130bf4b3cf6b50de Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Tue, 27 Dec 2011 02:45:00 +0100 Subject: use coderay_path to load version.rb --- lib/coderay.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/coderay.rb') diff --git a/lib/coderay.rb b/lib/coderay.rb index e54a73b..876d770 100644 --- a/lib/coderay.rb +++ b/lib/coderay.rb @@ -127,8 +127,6 @@ module CodeRay $CODERAY_DEBUG ||= false - require 'coderay/version' - CODERAY_PATH = File.join File.dirname(__FILE__), 'coderay' # Assuming the path is a subpath of lib/coderay/ @@ -136,6 +134,8 @@ module CodeRay File.join CODERAY_PATH, *path end + require coderay_path('version') + # helpers autoload :FileType, coderay_path('helpers', 'file_type') -- cgit v1.2.1