Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable to load gem with dashes #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion lib/require_reloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,44 @@ def watch(gem_name, opts={})
helper.remove_gem_module_if_defined(gem)
end
$".delete_if {|s| s.include?(gem)}
require gem
RequireReloader.require gem
opts[:callback].call(gem) if opts[:callback]
end
end
end

REQUIRE_ERRORS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
/^dlopen\([^)]*\): Library not loaded: (.+)$/i,
].freeze

def require(gem_name)
begin
begin
Kernel.require gem_name
rescue RuntimeError => e
raise e if e.is_a?(LoadError)
raise e, "There was an error while trying to load the gem '#{gem_name}'."
end
rescue LoadError => e
REQUIRE_ERRORS.find {|r| r =~ e.message }
raise if $1 != gem_name

if gem_name.include?('-')
begin
namespaced_gem_name = gem_name.tr("-", "/")
Kernel.require namespaced_gem_name
rescue LoadError => e
REQUIRE_ERRORS.find {|r| r =~ e.message }
raise if $1 != namespaced_gem_name
end
end
end
end

private

def expanded_gem_path(gem, preferred_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/require_reloader/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RequireReloader
VERSION = "0.2.1"
VERSION = "0.2.2"
end