Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Use qualified method name for calls to Kernel#load (rouge-ruby#1503)
Browse files Browse the repository at this point in the history
Rouge currently loads various components of the library using `Kernel#load`. In certain conditions, this can cause issues where
`load` is redefined at the global level. To ensure maximum
compatibility with other libraries, this commit replaces all calls to
`load` with qualified calls to `Kernel::load`. It also updates one call
to `Object.send` with a call to `Object::send` for consistency.
  • Loading branch information
pyrmont authored and mattt committed May 21, 2020
1 parent 723a265 commit c71f7b9
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions bin/rougify
Expand Up @@ -3,8 +3,8 @@

require 'pathname'
ROOT_DIR = Pathname.new(__FILE__).dirname.parent
load ROOT_DIR.join('lib/rouge.rb')
load ROOT_DIR.join('lib/rouge/cli.rb')
Kernel::load ROOT_DIR.join('lib/rouge.rb')
Kernel::load ROOT_DIR.join('lib/rouge/cli.rb')
Signal.trap('PIPE', 'SYSTEM_DEFAULT') if Signal.list.include? 'PIPE'

begin
Expand Down
6 changes: 3 additions & 3 deletions lib/rouge.rb
Expand Up @@ -12,8 +12,8 @@ module Rouge

class << self
def reload!
Object.send :remove_const, :Rouge
load __FILE__
Object::send :remove_const, :Rouge
Kernel::load __FILE__
end

# Highlight some text with a given lexer and formatter.
Expand All @@ -40,7 +40,7 @@ def highlight(text, lexer, formatter, &b)
#
# @api private
def load_file(path)
load File.join(LIB_DIR, "rouge/#{path}.rb")
Kernel::load File.join(LIB_DIR, "rouge/#{path}.rb")
end

# Load the lexers in the `lib/rouge/lexers` directory.
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexer.rb
Expand Up @@ -511,7 +511,7 @@ module Lexers
def self.load_lexer(relpath)
return if @_loaded_lexers.key?(relpath)
@_loaded_lexers[relpath] = true
load File.join(BASE_DIR, relpath)
Kernel::load File.join(BASE_DIR, relpath)
end
end
end
2 changes: 1 addition & 1 deletion lib/rouge/lexers/apache.rb
Expand Up @@ -13,7 +13,7 @@ class Apache < RegexLexer

# self-modifying method that loads the keywords file
def self.keywords
load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
keywords
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/gherkin.rb
Expand Up @@ -19,7 +19,7 @@ def self.detect?(text)

# self-modifying method that loads the keywords file
def self.keywords
load File.join(Lexers::BASE_DIR, 'gherkin/keywords.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'gherkin/keywords.rb')
keywords
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/isbl.rb
Expand Up @@ -10,7 +10,7 @@ class ISBL < RegexLexer
filenames '*.isbl'

def self.builtins
load File.join(Lexers::BASE_DIR, 'isbl/builtins.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'isbl/builtins.rb')
self.builtins
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/lasso.rb
Expand Up @@ -36,7 +36,7 @@ def start_inline?

# self-modifying method that loads the keywords file
def self.keywords
load File.join(Lexers::BASE_DIR, 'lasso/keywords.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'lasso/keywords.rb')
keywords
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/lua.rb
Expand Up @@ -25,7 +25,7 @@ def self.detect?(text)
end

def self.builtins
load File.join(Lexers::BASE_DIR, 'lua/builtins.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'lua/builtins.rb')
self.builtins
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/mathematica.rb
Expand Up @@ -56,7 +56,7 @@ def self.keywords

# The list of built-in symbols comes from a wolfram server and is created automatically by rake
def self.builtins
load File.join(Lexers::BASE_DIR, 'mathematica/builtins.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'mathematica/builtins.rb')
self.builtins
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/matlab.rb
Expand Up @@ -20,7 +20,7 @@ def self.keywords

# self-modifying method that loads the builtins file
def self.builtins
load File.join(Lexers::BASE_DIR, 'matlab/builtins.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'matlab/builtins.rb')
builtins
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/php.rb
Expand Up @@ -29,7 +29,7 @@ def initialize(*)
end

def self.builtins
load File.join(Lexers::BASE_DIR, 'php/builtins.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'php/builtins.rb')
self.builtins
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/sqf.rb
Expand Up @@ -55,7 +55,7 @@ def self.diag_commands
end

def self.commands
load File.join(Lexers::BASE_DIR, "sqf/commands.rb")
Kernel::load File.join(Lexers::BASE_DIR, "sqf/commands.rb")
@commands = self.commands
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/viml.rb
Expand Up @@ -14,7 +14,7 @@ class VimL < RegexLexer
mimetypes 'text/x-vim'

def self.keywords
load File.join(Lexers::BASE_DIR, 'viml/keywords.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'viml/keywords.rb')
self.keywords
end

Expand Down
3 changes: 1 addition & 2 deletions spec/visual/app.rb
Expand Up @@ -18,8 +18,7 @@ class VisualTestApp < Sinatra::Application
DEMOS = ROOT.join('lib/rouge/demos')

def reload_source!
Object.send :remove_const, :Rouge
load ROUGE_LIB
Rouge.reload!
end

def query_string
Expand Down

0 comments on commit c71f7b9

Please sign in to comment.