Browse files

First commit. Initial implementation.

  • Loading branch information...
0 parents commit 1143a4820cdb12841a20745065fff7bd736a0c5f @steveklabnik committed Mar 5, 2011
Showing with 114 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +47 −0 .rvmrc
  3. +4 −0 Gemfile
  4. +9 −0 Rakefile
  5. +8 −0 lib/require_relative.rb
  6. +3 −0 lib/require_relative/version.rb
  7. +21 −0 require_relative.gemspec
  8. 0 test/foo.rb
  9. +18 −0 test/require_relative_test.rb
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
47 .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 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in require_relative.gemspec
+gemspec
9 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 lib/require_relative.rb
@@ -0,0 +1,8 @@
+$:.delete(".")
+
+def require_relative file
+ $:.unshift(".")
+ ret = require file
+ $:.delete(".")
+ ret
+end
3 lib/require_relative/version.rb
@@ -0,0 +1,3 @@
+module RequireRelative
+ VERSION = "0.0.1"
+end
21 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
0 test/foo.rb
No changes.
18 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.