update_dependencies 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[..])
4
+
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ require 'update_dependencies'
8
+
9
+ UpdateDependencies.new(ARGV[0]).run_dependencies
@@ -0,0 +1,58 @@
1
+ module Bundler
2
+ class Dsl
3
+ def gemspec
4
+ puts "gemspec \n\n"
5
+ end
6
+ end
7
+ end
8
+
9
+ class UpdateDependencies
10
+ attr_reader :dependency_gemfile
11
+ def initialize(path_to_gemfile)
12
+ raise "Needs a location of a dependent Gemfile" unless path_to_gemfile
13
+ puts "source 'http://rubygems.org' \n\n"
14
+ @dependency_gemfile = Bundler::Dsl.new.eval_gemfile(path_to_gemfile)
15
+ end
16
+
17
+ def run_dependencies
18
+ dependency_gemfile.group_by {|g| g.groups.first }.each do |group, gem_sources|
19
+ in_group(group.to_s) do
20
+ gem_sources.each do |gem_source|
21
+ print_dependent_sources(gem_source, group)
22
+ print_version_sources(gem_source, group)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def spaces(group)
31
+ group.to_s == "default" ? "" : " "
32
+ end
33
+
34
+ def ref(source)
35
+ source.ref == "master" ? "" : ", ref => '" + source.ref + "'"
36
+ end
37
+
38
+ def in_group(group)
39
+ puts "\ngroup :" + group + " do" unless group == "default"
40
+ yield
41
+ puts "end" unless group == "default"
42
+ end
43
+
44
+ def locked_gemfile
45
+ @locked ||= Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock"))
46
+ end
47
+
48
+ def print_dependent_sources(gem_source, group)
49
+ locked_gemfile.sources.select {|s| gem_source.name == s.name}.
50
+ map {|s| puts spaces(group) + "gem '" + s.name + "', :git => '" + s.uri + "'" + ref(s)}
51
+ end
52
+
53
+ def print_version_sources(gem_source, group)
54
+ locked_gemfile.specs.reject {|s| locked_gemfile.sources.map(&:name).include?(s.name)}.
55
+ select {|s| s.name == gem_source.name}.
56
+ map {|s| puts spaces(group) + "gem '" + s.name + "', '" + s.version.version + "'"}
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: update_dependencies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - dougdroper
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Updates dependencies of gemfile from gemfile.lock
15
+ email:
16
+ - dougdroper@gmail.com
17
+ executables:
18
+ - update_dependencies
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - update_dependencies.rb
23
+ - bin/update_dependencies
24
+ homepage: https://gist.github.com/4566388
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - .
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.24
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Updates dependencies of gemfile from gemfile.lock
48
+ test_files: []
49
+ has_rdoc: