├── .gitignore ├── lib ├── bling.rb └── bling │ └── bling.rb ├── bling.gemspec ├── README.markdown └── bin └── bling /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | *.gem 4 | -------------------------------------------------------------------------------- /lib/bling.rb: -------------------------------------------------------------------------------- 1 | 2 | require File.join(File.dirname(__FILE__), 'bling', 'bling') 3 | -------------------------------------------------------------------------------- /bling.gemspec: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | 3 | Gem::Specification.new do |s| 4 | s.name = "bling" 5 | s.version = "0.1.1" 6 | s.date = "19Feb2010" 7 | s.summary = "bling bling gem management" 8 | s.email = "theath@gmail.com" 9 | s.homepage = "http://github.com/terrbear/bling" 10 | s.description = "drop in replacement for bundler" 11 | s.has_rdoc = false 12 | s.authors = ["Terry Heath"] 13 | s.files = FileList[ "lib/bling.rb", 14 | "lib/bling/**/*.rb", 15 | "bin/*"].to_a 16 | 17 | s.require_path = 'lib' 18 | 19 | s.bindir = 'bin' 20 | s.executables << "bling" 21 | end 22 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | Bling 2 | ===== 3 | 4 | I think Bundler is going to do a lot for gem management, but right now 5 | there are enough gem problems with it that I'd like to avoid it while 6 | playing with other Rails projects. As such, I've written this easy peasy 7 | gem manager that will: 8 | 9 | * Let you group gem dependencies by RAILS_ENV (see YAML below) 10 | * Show you what gems are needed for a given RAILS_ENV (rake bling:show) 11 | * Try to install those gems (bling install) 12 | 13 | Installation 14 | ------------ 15 | 16 | You'll need to install the bling gem, and then from your Rails root 17 | directory, just type `bling init`. There's one manual step you have to take, 18 | and then you get to fill out your bling.yml to explain your gem dependencies. 19 | 20 | Once you have your yaml filled out, you can type `bling install` and it 21 | should install the gems you need. 22 | 23 | YAML 24 | ---- 25 | 26 | When you run bling, you'll get a stock YAML file in your config directory 27 | that just has the Rails gem (currently 3.0.0.beta). If you want to add 28 | more gems, just add them either to the all section (meaning they will be 29 | required for every environment), or to a specifically named section, like 30 | test or production or development. Gems not listed in the all section will 31 | only be included if RAILS_ENV matches. 32 | 33 | Supported entries for gems are: name (gem name), version (allows ><~=), and 34 | lib (in case you're not meant to require the gem name). 35 | -------------------------------------------------------------------------------- /lib/bling/bling.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | class Bling 4 | def initialize(bling_file = "bling.yml") 5 | raise ArgumentError, "bling file not found" unless File.exists?(bling_file) 6 | @yaml = YAML::load_file(bling_file) 7 | end 8 | 9 | def require_env(env = nil) 10 | self.each_gem_for(env) do |entry| 11 | gem *([entry['name'], entry['version']].compact) 12 | require entry['lib'] || entry['name'] 13 | end 14 | end 15 | 16 | def list_gems(env = nil) 17 | self.each_gem_for(env) do |entry| 18 | line = entry['name'] 19 | line += " [#{entry['version']}]" if entry['version'] 20 | $stdout.puts line 21 | end 22 | end 23 | 24 | def install_gems(env = nil) 25 | only_if_present = lambda{|pre, val| val.to_s.empty? ? "" : " #{pre}#{val}"} 26 | gem_installed = false 27 | each_gem_for(env) do |entry| 28 | begin 29 | version = only_if_present.call('-v=', entry['version'].to_s.gsub(/[=~<>]/, '')) 30 | source = only_if_present.call('--source=', entry['source']) 31 | gem *([entry['name'], entry['version']].compact) 32 | rescue Gem::LoadError 33 | gem_installed = true 34 | $stdout.puts "installing #{entry['name']} #{version}" 35 | `gem install #{entry['name']} #{version} #{source} ` 36 | end 37 | end 38 | $stdout.puts "nothing to install!" unless gem_installed 39 | end 40 | 41 | protected 42 | def each_gem_for(env, &block) 43 | return unless @yaml 44 | (@yaml['all'] | (@yaml[env] || [])).each do |entry| 45 | yield entry if block_given? 46 | end 47 | end 48 | end 49 | 50 | 51 | -------------------------------------------------------------------------------- /bin/bling: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'rubygems' 4 | gem 'bling' 5 | require 'bling' 6 | 7 | $task = <<-rakefile 8 | require 'rubygems' 9 | gem 'bling' 10 | require 'bling' 11 | 12 | namespace :bling do 13 | desc 'shows gems that are required for the given env' 14 | task :show do 15 | file = File.join(File.dirname(__FILE__), "..", "..", "bling.yml") 16 | Bling.new(file).list_gems(ENV['RAILS_ENV']) 17 | end 18 | 19 | end 20 | rakefile 21 | 22 | $yaml = <<-yml 23 | all: 24 | - name: rails 25 | version: 3.0.0.beta 26 | yml 27 | 28 | $boot = <<-bootfile 29 | begin 30 | require 'rubygems' 31 | gem 'bling' 32 | require 'bling' 33 | end 34 | bootfile 35 | 36 | $final = <<-output 37 | You still need to do one thing before you're BLING BLINGing! 38 | 39 | You need to change the line in your application.rb from: 40 | 41 | Bundler.require :default, Rails.env 42 | 43 | to 44 | 45 | Bling.new(File.join(File.dirname(__FILE__), "..", "bling.yml")).require_env(Rails.env) 46 | output 47 | 48 | def init 49 | if !File.exists?("config/boot.rb") 50 | puts "Needs to be run from Rails root directory" 51 | exit(1) 52 | end 53 | 54 | File.open("lib/tasks/bling.rake", "w") do |f| 55 | f.write($task) 56 | end 57 | 58 | File.open("config/boot.rb", "w") do |f| 59 | f.write($boot) 60 | end 61 | 62 | File.open("bling.yml", "w") do |f| 63 | f.write($yaml) 64 | end 65 | 66 | puts $final 67 | end 68 | 69 | def install 70 | bling_file = "bling.yml" 71 | 72 | if !File.exists?(bling_file) 73 | puts "No bling file found" 74 | exit(1) 75 | end 76 | 77 | Bling.new(bling_file).install_gems(ENV['RAILS_ENV'] || "development") 78 | end 79 | 80 | if ARGV[0] == "install" 81 | install 82 | elsif ARGV[0] == "init" 83 | init 84 | else 85 | puts "Unrecognized command. Available command: install" 86 | end 87 | 88 | --------------------------------------------------------------------------------