Skip to content

Commit

Permalink
initial working version, whoop
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Feb 1, 2009
0 parents commit 678c8dc
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,22 @@
The MIT LICENSE

Copyright (c) 2009 Gabriel Horner

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
53 changes: 53 additions & 0 deletions README.rdoc
@@ -0,0 +1,53 @@
== Description

You have the beginnings of a ruby library and you want to access it quick.
You don't want to bother making a gemspec for it and uninstalling/reinstalling its gem
while you mess with it. Simply tell LocalGem what paths it should load for
your local gem and they will be loaded. Note that it doesn't matter how gem-like
your project is ie lib and bin directories etc. LocalGem *only* needs to know
the full path to your gem/library.

== Setup

Install the gem with:

sudo gem install cldwalker-local_gem -s http://gems.github.com

In ~/.local_gem.yml or a local local_gem.yml, specify a hash of
gem names pointing to an array of paths to load. See local_gem.yml.example
for an example.

== Use

The two main methods that LocalGem provides are local_gem() and local_require()
which map to gem() and require() respectively. Both methods will attempt
to load local gems that you have defined. If no gem is found than they resort to default
behavior.

There are 3 ways to use this library:

1. Mild: Call LocalGem with its class methods.

require 'local_gem'
LocalGem.local_gem 'alias'

2. Hot: Call methods directly having included it into your Kernel namespace.

require 'local_gem'
include LocalGem
local_gem 'alias'

3. Spicy: Override require() and gem() with local_require() and local_gem() respectively.

require 'local_gem'
require 'local_gem/override'
gem 'alias'

All three ways would add my local alias library to $LOAD_PATH. These three ways
also apply to local_require().

== Todo

* Support configuration without config file
* Tests!
* Autodetect new gems given local gem directories
48 changes: 48 additions & 0 deletions Rakefile
@@ -0,0 +1,48 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
begin
require 'rcov/rcovtask'

Rcov::RcovTask.new do |t|
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.rcov_opts = ["-T -x '/Library/Ruby/*'"]
t.verbose = true
end
rescue LoadError
puts "Rcov not available. Install it for rcov-related tasks with: sudo gem install rcov"
end

begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "local_gem"
s.description = "Loads any gem/library simply given its path. Great for nascent gems and/or for trying the latest code on a gem."
s.summary = s.description
s.email = "gabriel.horner@gmail.com"
s.homepage = "http://github.com/cldwalker/local_gem"
s.authors = ["Gabriel Horner"]
s.has_rdoc = true
s.files = FileList["VERSION.yml","Rakefile", "README.doc", "LICENSE.txt", "{bin,lib,test}/**/*"]
end

rescue LoadError
puts "Jeweler not available. Install it for jeweler-related tasks with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'test'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

task :default => :test
4 changes: 4 additions & 0 deletions VERSION.yml
@@ -0,0 +1,4 @@
---
:major: 0
:minor: 0
:patch: 0
37 changes: 37 additions & 0 deletions lib/local_gem.rb
@@ -0,0 +1,37 @@
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

module LocalGem
extend self
#attr_accessor :config_file

def local_config
@local_config ||= read_config
end

def read_config(file=nil)
@config_file = file || @config_file || (File.exists?('local_gem.yml') ? 'local_gem.yml' : File.expand_path(File.join("~",".local_gem.yml")))
hash = YAML::load(File.new(@config_file))
end

def local_gem(*args)
load_local_gem(args[0]) || gem(*args)
end

def local_require(lib)
load_local_gem(lib)
require(lib)
end

def load_local_gem(library)
if path = local_config[library]
path = [path] unless path.is_a?(Array)
path.map {|e| File.expand_path(e) }.each do |f|
$:.unshift(f) unless $:.include?(f)
end
true
else
false
end
end
end
15 changes: 15 additions & 0 deletions lib/local_gem/override.rb
@@ -0,0 +1,15 @@
module Kernel
alias_method :old_require, :require
alias_method :old_gem, :gem

def gem(*args)
load_local_gem(args[0]) || old_gem(*args)
end

def require(lib)
load_local_gem(lib)
old_require(lib)
end
end

send :include, LocalGem
28 changes: 28 additions & 0 deletions local_gem.gemspec
@@ -0,0 +1,28 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{local_gem}
s.version = "0.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gabriel Horner"]
s.date = %q{2009-02-01}
s.description = %q{Loads any gem/library simply given its path. Great for nascent gems and/or for trying the latest code on a gem.}
s.email = %q{gabriel.horner@gmail.com}
s.files = ["Rakefile", "README.doc", "LICENSE.txt", "lib/local_gem", "lib/local_gem/override.rb", "lib/local_gem.rb"]
s.has_rdoc = true
s.homepage = %q{http://github.com/cldwalker/local_gem}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.1}
s.summary = %q{Loads any gem/library simply given its path. Great for nascent gems and/or for trying the latest code on a gem.}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
end
else
end
end
4 changes: 4 additions & 0 deletions local_gem.yml.example
@@ -0,0 +1,4 @@
---
alias : ~/code/gems/alias/lib
core : ~/code/gems/core/lib
lightning : ~/code/gems/lightning/lib

0 comments on commit 678c8dc

Please sign in to comment.