Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
WIP make ruby 1.9/2.0 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit Shah committed Nov 8, 2013
1 parent 1b9a887 commit 5c77308
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source :rubygems
source 'https://rubygems.org'

gemspec :name => 'spitball-server'
gemspec :name => 'spitball-server'
15 changes: 10 additions & 5 deletions lib/spitball.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'ext/bundler_lockfile_parser'
require 'ext/bundler_fake_dsl'

$pwd = Dir.pwd

class Spitball
require 'spitball/client_common'
require 'spitball/digest'
Expand Down Expand Up @@ -33,7 +35,7 @@ def initialize(gemfile, gemfile_lock, options = {})
@gemfile = gemfile
@gemfile_lock = gemfile_lock
@options = options
@without = (options[:without] || []).map{|w| w.to_sym}
@without = options[:without].is_a?(Enumerable) ? options[:without].map(&:to_sym) : (options[:without] ? [options[:without].to_sym] : [])
@parsed_lockfile, @dsl = Bundler::FakeLockfileParser.new(gemfile_lock), Bundler::FakeDsl.new(gemfile)
raise "You need to run bundle install before you can use spitball" unless (@parsed_lockfile.dependencies.map{|d| d.name}.uniq.sort == @dsl.__gem_names.uniq.sort)
@groups_to_install = @dsl.__groups.keys - @without
Expand Down Expand Up @@ -74,7 +76,7 @@ def create_bundle

Dir.chdir(Repo.gemcache_path) do
@dsl.__gem_names.each do |spec|
spec_name = spec.first
spec_name = spec
if @groups_to_install.any?{|group| @dsl.__groups[group].include?(spec_name)}
if found_spec = @parsed_lockfile.specs.find {|spec| spec.name == spec_name}
install_gem(found_spec)
Expand Down Expand Up @@ -119,7 +121,10 @@ def install_and_copy_spec(name, version)
cache_dir = File.join(Repo.gemcache_path, "#{name}-#{::Digest::MD5.hexdigest([name, version, sources_opt(@parsed_lockfile.sources)].join('/'))}")
unless File.exist?(cache_dir)
FileUtils.mkdir_p(cache_dir)
out = `#{Spitball.gem_cmd} install #{name} -v'#{version}' --no-rdoc --no-ri --ignore-dependencies -i#{cache_dir} #{sources_opt(@parsed_lockfile.sources)} 2>&1`
out = ""
Dir.chdir($pwd) do
out = `#{Spitball.gem_cmd} install #{name} -v'#{version}' --no-rdoc --no-ri --ignore-dependencies -i#{cache_dir} #{sources_opt(@parsed_lockfile.sources)} 2>&1`
end
if $? == 0
puts out
else
Expand All @@ -133,7 +138,7 @@ def install_and_copy_spec(name, version)
end

def sources_opt(sources)
Array(ENV['SOURCE_OVERRIDE'] ||
Array(ENV['SOURCE_OVERRIDE'] ||
sources.
map{|s| s.remotes}.flatten.
map{|s| s.to_s}.
Expand All @@ -160,4 +165,4 @@ def gemfile_path
def tarball_path
Repo.bundle_path(digest, 'tgz')
end
end
end
2 changes: 1 addition & 1 deletion lib/spitball/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Spitball
VERSION = '0.6.1' unless const_defined?(:VERSION)
VERSION = '0.7.0' unless const_defined?(:VERSION)
end
6 changes: 3 additions & 3 deletions spec/spitball_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec/spec_helper'
require './spec/spec_helper'

describe Spitball do
before do
Expand Down Expand Up @@ -124,7 +124,7 @@
activerecord
end_lockfile
end

it "should use without" do
@spitball = Spitball.new(@gemfile, @lockfile)
mock(@spitball).install_and_copy_spec(anything, anything).times(9)
Expand Down Expand Up @@ -288,4 +288,4 @@
end
end
end
end
end
1 change: 1 addition & 0 deletions spitball-server.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |s|
s.executables = ['spitball-server', 'spitball-cache-cleanup']
s.require_paths = ["lib"]

s.add_dependency 'json'
s.add_dependency 'sinatra', '~> 1.2.0'
s.add_development_dependency 'rspec', "~> 1.3.0"
s.add_development_dependency 'diff-lcs'
Expand Down

0 comments on commit 5c77308

Please sign in to comment.