Skip to content

Commit

Permalink
add rubygems shim
Browse files Browse the repository at this point in the history
ported from old atomy; probably warrants another look, but it at least
works
  • Loading branch information
vito committed Jun 13, 2015
1 parent 4b302fb commit de81d6d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/atomy
Expand Up @@ -5,6 +5,7 @@ require "atomy"
require "atomy/bootstrap"
require "atomy/codeloader"
require "atomy/parser"
require "atomy/rubygems"

file, *_ = ARGV

Expand Down
44 changes: 44 additions & 0 deletions lib/atomy/rubygems.rb
@@ -0,0 +1,44 @@
# Patch up RubyGems/require (indirectly) to support loading
# Atomy gems

Gem.suffixes << ".ay"

module Kernel
alias atomy_original_gem_original_require gem_original_require
alias atomy_original_require require

def require(name)
if file = Atomy::CodeLoader.find_source(name)
Atomy::CodeLoader.require(file)
else
atomy_original_require(name)
end
end

def gem_original_require(name)
if file = Atomy::CodeLoader.find_source(name)
Atomy::CodeLoader.require(file)
else
atomy_original_gem_original_require(name)
end
end

module_function :require
module_function :gem_original_require

private :atomy_original_gem_original_require
private :atomy_original_require
end

# this is here so it's more likely to be filtered out of caller checks
#
# (e.g. sinatra/base)
class Atomy::Module
def require(path)
if path.start_with? "./"
Kernel.require(File.expand_path("../" + path, @file.to_s))
else
Kernel.require(path)
end
end
end

0 comments on commit de81d6d

Please sign in to comment.