dep 0.0.1.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/dep +75 -0
- data/lib/dep.rb +58 -0
- data/test/dep.rb +53 -0
- metadata +60 -0
data/bin/dep
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative "../lib/dep"
|
|
4
|
+
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "clap"
|
|
7
|
+
|
|
8
|
+
help = File.read(File.expand_path("../README", File.dirname(__FILE__)))
|
|
9
|
+
|
|
10
|
+
@list = Dep::List.new
|
|
11
|
+
@prerelease = false
|
|
12
|
+
|
|
13
|
+
FileUtils.touch(@list.path) unless File.exist?(@list.path)
|
|
14
|
+
|
|
15
|
+
def add(name)
|
|
16
|
+
res = Gem::SpecFetcher.fetcher.fetch(Gem::Dependency.new(name), false, true, @prerelease)
|
|
17
|
+
|
|
18
|
+
abort("Unable to find #{name}") if res.empty?
|
|
19
|
+
|
|
20
|
+
spec = res[-1][0]
|
|
21
|
+
lib = Dep::Lib.new(spec.name, spec.version)
|
|
22
|
+
|
|
23
|
+
@list.add(lib)
|
|
24
|
+
@list.save
|
|
25
|
+
|
|
26
|
+
puts "dep: added #{lib}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def rm(name)
|
|
30
|
+
@list.remove(Dep::Lib.new(name))
|
|
31
|
+
@list.save
|
|
32
|
+
|
|
33
|
+
puts "dep: removed #{name}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def check
|
|
37
|
+
if @list.missing_libraries.empty?
|
|
38
|
+
puts "dep: all cool"
|
|
39
|
+
else
|
|
40
|
+
puts "dep: the following libraries are missing"
|
|
41
|
+
|
|
42
|
+
@list.missing_libraries.each do |lib|
|
|
43
|
+
puts " %s" % lib
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def install
|
|
49
|
+
if @list.missing_libraries.empty?
|
|
50
|
+
abort("dep: nothing to install")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
@list.missing_libraries.each do |lib|
|
|
54
|
+
run "gem install #{lib}"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def run(cmd)
|
|
59
|
+
puts " #{cmd}"
|
|
60
|
+
`#{cmd}`
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if ARGV.empty?
|
|
64
|
+
check
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
commands = Clap.run ARGV,
|
|
68
|
+
"--pre" => lambda { @prerelease = true },
|
|
69
|
+
"--help" => lambda { abort(help) }
|
|
70
|
+
|
|
71
|
+
Clap.run commands,
|
|
72
|
+
"add" => method(:add),
|
|
73
|
+
"rm" => method(:rm),
|
|
74
|
+
"install" => method(:install),
|
|
75
|
+
"check" => method(:check)
|
data/lib/dep.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Dep
|
|
2
|
+
class List
|
|
3
|
+
attr :path
|
|
4
|
+
|
|
5
|
+
def initialize(path = File.join(Dir.pwd, ".gems"))
|
|
6
|
+
@path = path
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def add(lib)
|
|
10
|
+
remove(lib)
|
|
11
|
+
libraries.push(lib)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def remove(lib)
|
|
15
|
+
libraries.delete_if { |e| e.name == lib.name }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def libraries
|
|
19
|
+
@libraries ||= File.readlines(path).map { |line| Lib[line] }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def missing_libraries
|
|
23
|
+
libraries.reject(&:available?)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def save
|
|
27
|
+
File.open(path, "w") do |file|
|
|
28
|
+
libraries.each do |lib|
|
|
29
|
+
file.puts lib.to_s
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Lib < Struct.new(:name, :version)
|
|
36
|
+
def self.[](line)
|
|
37
|
+
if line =~ /^(\S+) -v (\S+)$/
|
|
38
|
+
return new($1, $2)
|
|
39
|
+
else
|
|
40
|
+
abort("Invalid requirement found: #{line}")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def available?
|
|
45
|
+
Gem::Specification.find_by_name(name, version)
|
|
46
|
+
rescue Gem::LoadError
|
|
47
|
+
return false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def to_s
|
|
51
|
+
"#{name} -v #{version}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def ==(other)
|
|
55
|
+
to_s == other.to_s
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/test/dep.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require "cutest"
|
|
2
|
+
|
|
3
|
+
require_relative "../lib/dep"
|
|
4
|
+
|
|
5
|
+
# Dep::Lib
|
|
6
|
+
scope do
|
|
7
|
+
test "parsing" do
|
|
8
|
+
lib = Dep::Lib["ohm-contrib -v 1.0.rc1"]
|
|
9
|
+
|
|
10
|
+
assert_equal "ohm-contrib", lib.name
|
|
11
|
+
assert_equal "1.0.rc1", lib.version
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "availability of existing gem" do
|
|
15
|
+
lib = Dep::Lib.new("cutest", "1.1.3")
|
|
16
|
+
assert lib.available?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test "non-availability of missing gem" do
|
|
20
|
+
lib = Dep::Lib.new("rails", "3.0")
|
|
21
|
+
assert ! lib.available?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test "to_s" do
|
|
25
|
+
lib = Dep::Lib.new("cutest", "1.1.3")
|
|
26
|
+
assert_equal "cutest -v 1.1.3", lib.to_s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Dep::List
|
|
31
|
+
scope do
|
|
32
|
+
setup do
|
|
33
|
+
Dep::List.new(File.expand_path(".gems", File.dirname(__FILE__)))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test do |list|
|
|
37
|
+
lib1 = Dep::Lib.new("ohm-contrib", "1.0.rc1")
|
|
38
|
+
lib2 = Dep::Lib.new("cutest", "1.1.3")
|
|
39
|
+
|
|
40
|
+
assert list.libraries.include?(lib1)
|
|
41
|
+
assert list.libraries.include?(lib2)
|
|
42
|
+
|
|
43
|
+
assert_equal 1, list.missing_libraries.size
|
|
44
|
+
assert list.missing_libraries.include?(lib1)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test do |list|
|
|
48
|
+
list.add(Dep::Lib.new("cutest", "2.0"))
|
|
49
|
+
|
|
50
|
+
assert ! list.libraries.include?(Dep::Lib.new("cutest", "1.1.3"))
|
|
51
|
+
assert list.libraries.include?(Dep::Lib.new("cutest", "2.0"))
|
|
52
|
+
end
|
|
53
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dep
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.rc1
|
|
5
|
+
prerelease: 6
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Cyril David
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-01-19 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: clap
|
|
16
|
+
requirement: &2151896480 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *2151896480
|
|
25
|
+
description: Specify your project's dependencies in one file.
|
|
26
|
+
email:
|
|
27
|
+
- cyx.ucron@gmail.com
|
|
28
|
+
executables:
|
|
29
|
+
- dep
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- bin/dep
|
|
34
|
+
- lib/dep.rb
|
|
35
|
+
- test/dep.rb
|
|
36
|
+
homepage: http://github.com/twpil/dep
|
|
37
|
+
licenses: []
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options: []
|
|
40
|
+
require_paths:
|
|
41
|
+
- lib
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
none: false
|
|
44
|
+
requirements:
|
|
45
|
+
- - ! '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>'
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 1.3.1
|
|
54
|
+
requirements: []
|
|
55
|
+
rubyforge_project:
|
|
56
|
+
rubygems_version: 1.8.11
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 3
|
|
59
|
+
summary: Dependencies manager
|
|
60
|
+
test_files: []
|