Skip to content

Commit

Permalink
First commit. Initial implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Mar 6, 2011
0 parents commit 1143a48
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
47 changes: 47 additions & 0 deletions .rvmrc
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory

# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
environment_id="ruby-1.8.7-p330@require_relative"

#
# First we attempt to load the desired environment directly from the environment
# file, this is very fast and efficicent compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
#
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create "$environment_id"
fi

#
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
# it be automatically loaded, uncomment the following and adjust the filename if
# necessary.
#
# filename=".gems"
# if [[ -s "$filename" ]] ; then
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
# fi

#
# If you use bundler and would like to run bundle each time you enter the
# directory you can uncomment the following code.
#
# # Ensure that Bundler is installed, install it if it is not.
# if ! command -v bundle ; then
# printf "The rubygem 'bundler' is not installed, installing it now.\n"
# gem install bundler
# fi
#
# # Bundle while redcing excess noise.
# printf "Bundling your gems this may take a few minutes on a fresh clone.\n"
# bundle | grep -v 'Using' | grep -v 'complete' | sed '/^$/d'
#

4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in require_relative.gemspec
gemspec
9 changes: 9 additions & 0 deletions Rakefile
@@ -0,0 +1,9 @@
require 'bundler'
Bundler::GemHelper.install_tasks

task :default => :test

require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = "test/*_test.rb"
end
8 changes: 8 additions & 0 deletions lib/require_relative.rb
@@ -0,0 +1,8 @@
$:.delete(".")

def require_relative file
$:.unshift(".")
ret = require file
$:.delete(".")
ret
end
3 changes: 3 additions & 0 deletions lib/require_relative/version.rb
@@ -0,0 +1,3 @@
module RequireRelative
VERSION = "0.0.1"
end
21 changes: 21 additions & 0 deletions require_relative.gemspec
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "require_relative/version"

Gem::Specification.new do |s|
s.name = "require_relative"
s.version = RequireRelative::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Steve Klabnik"]
s.email = ["steve@steveklabnik.com"]
s.homepage = ""
s.summary = %q{This backports require_relative to Ruby 1.8.}
s.description = %q{In Ruby 1.9.2, "." was removed from $:. This is a good idea, for security reasons. This gem backports this to Ruby 1.8.}

s.add_development_dependency "minitest"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end
Empty file added test/foo.rb
Empty file.
18 changes: 18 additions & 0 deletions test/require_relative_test.rb
@@ -0,0 +1,18 @@
require 'rubygems'
require 'bundler'
require 'minitest/autorun'

require 'require_relative'

class RequireRelativeTest < MiniTest::Unit::TestCase

def test_current_dir_not_in_load_path
assert_nil $:.detect{|i| i == "."}
end

def test_require_relative
assert require_relative('test/foo')
end

end

0 comments on commit 1143a48

Please sign in to comment.