Module LocalGem::Singleton

  1. lib/local_gem.rb

Attributes

config [RW]
config_file [RW]

Public instance methods

config ()

Holds the mapping of local gems and their paths to load.

[show source]
# File lib/local_gem.rb, line 25
    def config
      @config ||= read_config
    end
load_local_gem (library)

Adds a given library’s path (specified in config) to the beginning of $LOAD_PATH.

[show source]
# 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
local_gem (*args)

Loads the local gem if found or defaults to a normal gem call.

[show source]
# File lib/local_gem.rb, line 43
    def local_gem(*args)
      load_local_gem(args[0]) || gem(*args)
    end
local_require (lib)

Loads the local gem if found and then does a normal require on it.

[show source]
# File lib/local_gem.rb, line 48
    def local_require(lib)
      load_local_gem(lib)
      require(lib)
    end
read_config ()

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.

[show source]
# 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
setup_config (config=nil, &block)

Takes either a hash or a block and initializes config().

[show source]
# File lib/local_gem.rb, line 38
    def setup_config(config=nil, &block)
      @config = config || ConfigStruct.block_to_hash(block)
    end