Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4b304bd6612b1209cf9a4099e2cb25c49cf58a62 @ndbroadbent committed Mar 24, 2012
Showing with 181 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE
  4. +79 −0 README.md
  5. +2 −0 Rakefile
  6. +17 −0 bundler_local_development.gemspec
  7. +36 −0 lib/bundler/local_development.rb
  8. +1 −0 lib/bundler_local_development.rb
  9. +3 −0 lib/bundler_local_development/version.rb
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in bundler_local_development.gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Nathan Broadbent
+
+MIT License
+
+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.
@@ -0,0 +1,79 @@
+# Bundler - Local Development
+
+### Provides a simple way to switch between local and installed gems.
+
+Since this gem overrides bundler itself, it is installed and required in an unusual way.
+It is required *within* your Gemfile, and is not meant to be used in your application.
+
+## Installation
+
+Add these lines to your application's Gemfile:
+
+ gem 'bundler_local_development', :group => :development, :require => false
+ begin
+ require 'bundler_local_development'
+ Bundler.development_gems = [/foo/, 'bar', /baz/]
+ rescue LoadError
+ end
+
+And then execute:
+
+ $ bundle
+
+
+## Usage
+
+* Call `Bundler.development_gems = [...]` in your Gemfile, to configure
+ your default set of local gems.
+ You can provide regular expressions or strings to match gem names.
+* Set $DEV_GEMS to add extra gems to this list (comma separated list of gem names).
+
+If the $GEM_DEV environment variable is set, bundler will search for gems in the
+path specified by $GEM_DEV_DIR (or $HOME/code/gems if not set.)
+
+
+## Shell shortcut
+
+In order to make the most of this gem, you need a quick way to enable or disable it.
+Add the following function to your `~/.bashrc` or `~/.zshrc`:
+
+```bash
+# Gem development shortcuts
+# Toggle between gem development and production mode
+# (Set / unset $GEM_DEV variable)
+gdv() {
+ local flag_var="GEM_DEV"
+ if env | grep -q "^$flag_var="; then
+ unset $flag_var
+ else
+ export $flag_var=true
+ fi
+}
+```
+
+Now you will be able to enable or disable the gem by typing `gdv`.
+
+
+## Indicator in Shell Prompt
+
+Finally, you might want to know whether or not the gem is enabled.
+
+Add the following function to your `~/.bashrc` or `~/.zshrc`:
+
+```bash
+# When developing gems ($GEM_DEV is exported), display a hammer and pick
+parse_gem_development() {
+ if env | grep -q "^GEM_DEV="; then echo "\[\e[0;33m\]⚒ "; fi
+}
+```
+
+Then, use `$(parse_gem_development)` to display the indicator in your prompt.
+
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/bundler_local_development/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Nathan Broadbent"]
+ gem.email = ["nathan.f77@gmail.com"]
+ gem.description = %q{Provides a simple way to switch between local and installed gems.}
+ gem.summary = %q{Switch to a set of local gems with a single command}
+ gem.homepage = "https://github.com/ndbroadbent/bundler_local_development"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "bundler_local_development"
+ gem.require_paths = ["lib"]
+ gem.version = BundlerLocalDevelopment::VERSION
+end
@@ -0,0 +1,36 @@
+#
+# Provides a simple way to switch between local and installed gems.
+#
+# * Call `Bundler.development_gems=[]` in your Gemfile, to configure
+# the default set of gems to override with local copies.
+# * Set $DEVELOPMENT_GEMS to add extra gems to this list.
+#
+# If the $GEM_DEV environment variable is set, bundler will search for gems in the
+# path specified by $GEM_DEV_DIR (or $HOME/code/gems if not set.)
+
+module Bundler
+ class << self
+ def development_gems=(search_strings)
+ @@development_gems = search_strings
+ end
+ def development_gems
+ (@@development_gems ||= []) +
+ ENV['DEV_GEMS'].to_s.split(',').map(&:strip).select{|s| s != "" })
+ end
+ end
+
+ class Dsl
+ alias :gem_without_development :gem
+ def gem_with_development(name, *args)
+ if ENV['GEM_DEV'] && Bundler.development_gems.any?{ |s| name[s] }
+ gem_dev_dir = ENV['GEM_DEV_DIR'] || "#{`echo $HOME`.strip}/code/gems"
+ path = File.join(gem_dev_dir, name)
+ if File.exist?(path)
+ return gem_without_development name, :path => path
+ end
+ end
+ gem_without_development(name, *args)
+ end
+ alias :gem :gem_with_development
+ end
+end
@@ -0,0 +1 @@
+require 'bundler/local_development'
@@ -0,0 +1,3 @@
+module BundlerLocalDevelopment
+ VERSION = "0.0.1"
+end

0 comments on commit 4b304bd

Please sign in to comment.