Attributes
config | [RW] | |
config_file | [RW] |
Public instance methods
Holds the mapping of local gems and their paths to load.
# File lib/local_gem.rb, line 25 def config @config ||= read_config end
Adds a given library’s path (specified in config) to the beginning of $LOAD_PATH.
# File lib/local_gem.rb, line 54 def load_local_gem(library) if path = config[:gems][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
Loads the local gem if found or defaults to a normal gem call.
# File lib/local_gem.rb, line 43 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.
# File lib/local_gem.rb, line 48 def local_require(lib) load_local_gem(lib) require(lib) 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.
# File lib/local_gem.rb, line 32 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().
# File lib/local_gem.rb, line 38 def setup_config(config=nil, &block) @config = config || ConfigStruct.block_to_hash(block) end