dependencies 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/dep CHANGED
@@ -1,13 +1,41 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ require "fileutils"
3
4
  require "dependencies/dep"
5
+ require "thor"
4
6
 
5
- env = ARGV.first
7
+ class App < Thor
8
+ def list(env = nil)
9
+ deps.filter(env).each { |dep| puts dep }
10
+ deps.require(env)
11
+ end
6
12
 
7
- deps = Dep.new(File.read("dependencies"))
13
+ def vendor(name)
14
+ dep = dependency(name) || flunk("Dependency #{name} not found in dependencies.")
15
+ dep.url || flunk("Don't know where to vendor #{name} from (no URL given...)")
8
16
 
9
- deps.filter(env).each do |dep|
10
- puts dep
17
+ FileUtils.mkdir("vendor") unless File.directory?("vendor")
18
+
19
+ Dir.chdir("vendor") do
20
+ system "git clone #{dep.url} #{dep.name} -q"
21
+ Dir.chdir(dep.name) { FileUtils.rm_rf(".git") }
22
+ end
23
+ end
24
+
25
+ protected
26
+
27
+ def deps
28
+ @deps ||= Dep.new(File.read("dependencies"))
29
+ end
30
+
31
+ def dependency(name)
32
+ deps.find { |dep| dep.name == name }
33
+ end
34
+
35
+ def flunk(message)
36
+ $stderr.puts(message)
37
+ exit 1
38
+ end
11
39
  end
12
40
 
13
- deps.require(env)
41
+ App.start
data/dependencies.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "dependencies"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.summary = "Specify your project's dependencies in one file."
5
5
  s.authors = ["Damian Janowski", "Michel Martens"]
6
6
  s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
@@ -9,5 +9,7 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.executables << "dep"
11
11
 
12
- s.files = ["Rakefile", "bin/dep", "dependencies.gemspec", "lib/dependencies/dep.rb", "lib/dependencies.rb", "test/dependencies_test.rb", "test/vendor/barz-2.0", "test/vendor/baz-1.0"]
12
+ s.files = ["Rakefile", "bin/dep", "dependencies.gemspec", "lib/dependencies/dep.rb", "lib/dependencies.rb", "test/dependencies_test.rb", "test/vendor/bar/lib", "test/vendor/barz-2.0/lib", "test/vendor/baz-1.0/lib"]
13
+
14
+ s.add_dependency("thor", "~> 0.9")
13
15
  end
@@ -1,15 +1,15 @@
1
1
  class Dep
2
- attr :dependencies
3
-
4
2
  class Dependency
5
3
  attr :name
6
4
  attr :version
7
5
  attr :environment
6
+ attr :url
8
7
 
9
- def initialize(name, version = nil, environment = nil)
8
+ def initialize(name, version = nil, environment = nil, url = nil)
10
9
  @name = name
11
10
  @version = version if version && !version.empty?
12
11
  @environment = environment ? environment.split(/\, ?/) : []
12
+ @url = url
13
13
  end
14
14
 
15
15
  def for_environment?(env)
@@ -50,13 +50,17 @@ class Dep
50
50
  end
51
51
  end
52
52
 
53
+ include Enumerable
54
+
55
+ attr :dependencies
56
+
53
57
  def initialize(dependencies)
54
58
  @dependencies = []
55
59
  @missing = []
56
60
 
57
61
  dependencies.each_line do |line|
58
- next unless line =~ /^([\w\-_]+) ?([<~=> \d\.]+)?( \(([\w, ]+)\))?$/
59
- @dependencies << Dependency.new($1, $2, $4)
62
+ next unless line =~ /^([\w\-_]+) ?([<~=> \d\.]+)?(?: \(([\w, ]+)\))?(?: ([a-z]+:\/\/.+?))?$/
63
+ @dependencies << Dependency.new($1, $2, $3, $4)
60
64
  end
61
65
  end
62
66
 
@@ -1,5 +1,5 @@
1
1
  require "rubygems"
2
- require "ruby-debug"
2
+ require "open3"
3
3
 
4
4
  gem "contest"
5
5
 
@@ -81,22 +81,86 @@ class DependenciesTest < Test::Unit::TestCase
81
81
 
82
82
  context "binary" do
83
83
  def dep(args = nil)
84
- %x{ruby -I#{LIB} -rubygems #{File.expand_path(File.join("../bin/dep"))} #{args}}
84
+ out, err = nil
85
+
86
+ Open3.popen3("ruby -I#{LIB} -rubygems #{File.expand_path(File.join("../bin/dep"))} #{args}") do |stdin, stdout, stderr|
87
+ out = stdout.read
88
+ err = stderr.read
89
+ end
90
+
91
+ [out, err]
85
92
  end
86
93
 
87
- test "prints all dependencies" do
88
- with_dependencies "foo ~> 1.0\nbar" do
89
- out = dep
94
+ context "list" do
95
+ test "prints all dependencies" do
96
+ with_dependencies "foo ~> 1.0\nbar" do
97
+ out, err = dep "list"
98
+
99
+ assert_equal "foo ~> 1.0\nbar\n", out
100
+ end
101
+ end
90
102
 
91
- assert_equal "foo ~> 1.0\nbar\n", out
103
+ test "prints dependencies based on given environment" do
104
+ with_dependencies "foo 1.0 (test)\nbar (development)\nbarz 2.0\nbaz 0.1 (test)" do
105
+ out, err = dep "list test"
106
+
107
+ assert_equal "foo 1.0 (test)\nbarz 2.0\nbaz 0.1 (test)\n", out
108
+ end
92
109
  end
93
110
  end
94
111
 
95
- test "prints dependencies based on given environment" do
96
- with_dependencies "foo 1.0 (test)\nbar (development)\nbarz 2.0\nbaz 0.1 (test)" do
97
- out = dep "test"
112
+ context "vendor" do
113
+ setup do
114
+ @dir = create_repo("foobar")
115
+ end
116
+
117
+ test "vendors dependencies" do
118
+ with_dependencies "foobar 1.0 file://#{@dir}" do
119
+ out, err = dep "vendor foobar"
120
+
121
+ assert File.exist?("vendor/foobar/lib/foobar.rb")
122
+ assert !File.exist?("vendor/foobar/.git")
123
+ end
124
+ end
125
+
126
+ test "complains when no URL given" do
127
+ with_dependencies "foobar 1.0" do
128
+ out, err = dep "vendor foobar"
129
+
130
+ assert_match %r{Don't know where to vendor foobar from \(no URL given...\)}, err
131
+ end
132
+ end
133
+
134
+ test "complains when the dependency is not found" do
135
+ with_dependencies "foobar 1.0" do
136
+ out, err = dep "vendor qux"
137
+
138
+ assert_match %r{Dependency qux not found.}, err
139
+ end
140
+ end
141
+
142
+ teardown do
143
+ FileUtils.rm_rf(@dir)
144
+ end
145
+
146
+ def create_repo(name)
147
+ dir = File.expand_path(File.join(File.dirname(__FILE__), "tmp", name))
148
+
149
+ FileUtils.rm_rf(dir)
150
+ FileUtils.rm_rf("vendor/#{name}")
151
+ FileUtils.mkdir_p(dir)
152
+
153
+ Dir.chdir(dir) do
154
+ `git init`
155
+
156
+ FileUtils.mkdir("lib")
157
+ FileUtils.touch("lib/#{name}.rb")
158
+
159
+ `git add lib`
160
+ `git commit -m 'Lorem.'`
161
+ end
98
162
 
99
- assert_equal "foo 1.0 (test)\nbarz 2.0\nbaz 0.1 (test)\n", out
163
+ dir
100
164
  end
101
165
  end
102
166
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski
@@ -10,10 +10,19 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-24 00:00:00 -03:00
13
+ date: 2009-06-25 00:00:00 -03:00
14
14
  default_executable:
15
- dependencies: []
16
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: thor
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "0.9"
25
+ version:
17
26
  description:
18
27
  email:
19
28
  - djanowski@dimaion.com