Permalink
Browse files

made better rdoc

  • Loading branch information...
cldwalker committed Feb 2, 2009
1 parent a366c3e commit 192445811bd1a017c6bab085382401205162037c
Showing with 17 additions and 14 deletions.
  1. +1 −1 README.rdoc
  2. +3 −2 lib/config_struct.rb
  3. +11 −3 lib/local_gem.rb
  4. +2 −0 lib/local_gem/override.rb
  5. +0 −8 test/test_helper.rb
View
@@ -23,7 +23,7 @@ to a path or an array of paths to load. You can do this with LocalGem.setup_conf
Or a config file at either a local local_gem.yml or ~/.local_gem.yml .
See local_gem.yml.example for an example config file.
== Use
== Usage
The two main methods that LocalGem provides are local_gem() and local_require()
which map to gem() and require() respectively. Both methods will attempt
View
@@ -1,6 +1,7 @@
require 'ostruct'
class ConfigStruct < OpenStruct
# Converts the data within the given block to hash
def self.block_to_hash(block=nil)
config = self.new
if block
@@ -11,7 +12,7 @@ def self.block_to_hash(block=nil)
end
end
def to_hash
def to_hash #:nodoc:
@table
end
end
end
View
@@ -4,44 +4,52 @@
module LocalGem
extend self
def local_require(path)
def local_require(path) #:nodoc:
Singleton.local_require(path)
end
def local_gem(*args)
def local_gem(*args) #:nodoc:
Singleton.local_gem(*args)
end
def setup_config(config, &block)
def setup_config(config, &block) #:nodoc:
Singleton.setup_config(config, &block)
end
module Singleton
extend self
attr_accessor :config, :config_file
# Holds the mapping of local gems and their paths to load.
def config
@config ||= read_config
end
# Reads config from @config_file and returns a hash.
# @config_file can be set via its accessor. Otherwise it defaults to a local local_gem.yml or
# ~/.local_gem.yml.
def read_config
@config_file ||= ['local_gem.yml', File.join("~", ".local_gem.yml")].detect {|e| File.exists?(File.expand_path(e)) }
@config_file ? YAML::load(File.new(File.expand_path(@config_file))) : {:gems=>{}}
end
# Takes either a hash or a block and initializes config().
def setup_config(config=nil, &block)
@config = config || ConfigStruct.block_to_hash(block)
end
# Loads the local gem if found or defaults to a normal gem call.
def local_gem(*args)
load_local_gem(args[0]) || gem(*args)
end
# Loads the local gem if found and then does a normal require on it.
def local_require(lib)
load_local_gem(lib)
require(lib)
end
# Adds a given library's path (specified in config) to the beginning of $LOAD_PATH.
def load_local_gem(library)
if path = config[:gems][library]
path = [path] unless path.is_a?(Array)
@@ -2,10 +2,12 @@ module Kernel
alias_method :old_require, :require
alias_method :old_gem, :gem
# Overrides gem() to behave like LocalGem::Singleton.local_gem().
def gem(*args)
LocalGem::Singleton.load_local_gem(args[0]) || old_gem(*args)
end
# Overrides require() to behave like LocalGem::Singleton.local_require().
def require(lib)
LocalGem::Singleton.load_local_gem(lib)
old_require(lib)
View
@@ -1,17 +1,9 @@
require 'rubygems'
require 'test/unit'
require 'context' #gem install jeremymcanally-context -s http://gems.github.com
#require 'stump' #gem install jeremymcanally-stump -s http://gems.github.com
require 'mocha'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'local_gem'
class Test::Unit::TestCase
end
#from ActiveSupport
class Hash
def slice(*keys)
reject { |key,| !keys.include?(key) }
end
end

0 comments on commit 1924458

Please sign in to comment.