library 0.1.0
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/.ruby +57 -0
- data/.yardopts +6 -0
- data/COPYING.rdoc +30 -0
- data/HISTORY.rdoc +13 -0
- data/README.md +177 -0
- data/lib/library.rb +532 -0
- data/lib/library/autoload.rb +14 -0
- data/lib/library/core_ext.rb +34 -0
- data/lib/library/domain.rb +244 -0
- data/lib/library/errors.rb +49 -0
- data/lib/library/feature.rb +207 -0
- data/lib/library/kernel.rb +81 -0
- data/lib/library/ledger.rb +642 -0
- data/lib/library/metadata.rb +398 -0
- data/lib/library/rbconfig.rb +65 -0
- data/lib/library/rubygems.rb +19 -0
- data/lib/library/rubylib.rb +206 -0
- data/lib/library/version.rb +387 -0
- data/lib/ubylibs.rb +8 -0
- data/qed/01_loading.rdoc +14 -0
- data/qed/02_library.rdoc +55 -0
- data/qed/03_ledger.rdoc +30 -0
- data/qed/04_version.rdoc +101 -0
- data/qed/applique/check.rb +11 -0
- data/qed/applique/project.rb +34 -0
- data/qed/fixtures/foo/.ruby +5 -0
- data/qed/fixtures/foo/lib/foo.rb +1 -0
- data/qed/fixtures/tryme/1.0/.ruby +6 -0
- data/qed/fixtures/tryme/1.0/lib/tryme.rb +1 -0
- data/qed/fixtures/tryme/1.1/.ruby +7 -0
- data/qed/fixtures/tryme/1.1/lib/tryme.rb +1 -0
- data/qed/helpers/new_project.rdoc +29 -0
- data/qed/helpers/projects.rdoc +56 -0
- data/test/case_ledger.rb +23 -0
- data/test/case_library.rb +13 -0
- data/test/case_version.rb +89 -0
- data/test/fixture/.ruby +56 -0
- data/test/fixture/lib/foo.rb +7 -0
- data/test/helper.rb +2 -0
- metadata +144 -0
data/lib/ubylibs.rb
ADDED
data/qed/01_loading.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
= Load and Require
|
2
|
+
|
3
|
+
The #library method can be used to constrain a library to a particular
|
4
|
+
version.
|
5
|
+
|
6
|
+
library('tryme', '1.1')
|
7
|
+
|
8
|
+
If we try to constrain a library to an incompatible version a VersionConflit
|
9
|
+
will be raised.
|
10
|
+
|
11
|
+
expect Library::VersionConflict do
|
12
|
+
library('tryme', '1.0')
|
13
|
+
end
|
14
|
+
|
data/qed/02_library.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= Library Instances
|
2
|
+
|
3
|
+
The Library class can be initialized given the location of the project.
|
4
|
+
|
5
|
+
tryme10 = Library.new(fixtures + '/tryme/1.0')
|
6
|
+
tryme11 = Library.new(fixtures + '/tryme/1.1')
|
7
|
+
|
8
|
+
With a library instance in hand we can query it for information about itself.
|
9
|
+
|
10
|
+
tryme10.name.assert == "tryme"
|
11
|
+
tryme11.name.assert == "tryme"
|
12
|
+
|
13
|
+
tryme10.version.to_s.assert == "1.0"
|
14
|
+
tryme11.version.to_s.assert == "1.1"
|
15
|
+
|
16
|
+
Secondary information, taken from a project's .ruby file, can be queried via
|
17
|
+
the #metadata method.
|
18
|
+
|
19
|
+
tryme10.metadata['resources']['home'].assert == "http://tryme.foo"
|
20
|
+
tryme11.metadata['resources']['home'].assert == "http://tryme.foo"
|
21
|
+
|
22
|
+
Of course, the most important function of a library is to load and require
|
23
|
+
a script. With an Library instance in hand this can be achieved directly.
|
24
|
+
|
25
|
+
tryme10.load('tryme.rb')
|
26
|
+
$tryme_message.assert == "Try Me v1.0"
|
27
|
+
|
28
|
+
But if we try to load from another version, we will get a VersionConflict
|
29
|
+
error.
|
30
|
+
|
31
|
+
expect Library::VersionConflict do
|
32
|
+
tryme11.load('tryme.rb')
|
33
|
+
end
|
34
|
+
|
35
|
+
However, we can bypass this constraint (if we know what you are doing!) with
|
36
|
+
the :force option.
|
37
|
+
|
38
|
+
tryme11.load('tryme.rb', :force=>true)
|
39
|
+
$tryme_message.assert == "Try Me v1.1"
|
40
|
+
|
41
|
+
Notice that when requiring files directly via a Library instance, if a file
|
42
|
+
is required from two different versions of a library, a VersionConflict
|
43
|
+
error will be rasied.
|
44
|
+
|
45
|
+
expect Library::VersionConflict do
|
46
|
+
tryme11.require('tryme')
|
47
|
+
end
|
48
|
+
|
49
|
+
But there is no error if we use the active version.
|
50
|
+
|
51
|
+
tryme10.require('tryme')
|
52
|
+
|
53
|
+
TODO: In the future, I think we will put in a version check, and a :force
|
54
|
+
option to override.
|
55
|
+
|
data/qed/03_ledger.rdoc
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
= The Ledger
|
2
|
+
|
3
|
+
At the heart of Library lies a Ledger object. It is essentially a Hash of
|
4
|
+
library names indexing Library objects stored in the global $LEDGER variable.
|
5
|
+
|
6
|
+
$LEDGER.keys.sort.assert == ['foo', 'ruby', 'tryme']
|
7
|
+
|
8
|
+
The Library class redirects a number of calls to the $LEDGER, so we
|
9
|
+
could invoke the same methods on it instead.
|
10
|
+
|
11
|
+
Library.names.assert == $LEDGER.keys
|
12
|
+
|
13
|
+
Which we choose to use is really a matter of taste. The Roll::Library
|
14
|
+
methods were designed for readability, whereas $LEDGER is used internally.
|
15
|
+
For the rest of this demo we will use $LEDGER since this demonstration
|
16
|
+
is specifically about it.
|
17
|
+
|
18
|
+
The values of $LEDGER will always be either a Library object or an
|
19
|
+
array of Library objects, of the same name but differnt versions.
|
20
|
+
|
21
|
+
When a particular library is activated for the first time the corresponding
|
22
|
+
array value will be replaced by the library.
|
23
|
+
|
24
|
+
$LEDGER['tryme'].assert.is_a?(Array)
|
25
|
+
|
26
|
+
library('tryme')
|
27
|
+
|
28
|
+
$LEDGER['tryme'].assert.is_a?(Library)
|
29
|
+
|
30
|
+
|
data/qed/04_version.rdoc
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
= Version Class
|
2
|
+
|
3
|
+
Librarys has a versioj class which it uses to compare
|
4
|
+
versions via vairous constraints.
|
5
|
+
|
6
|
+
Load the library.
|
7
|
+
|
8
|
+
require 'library/version'
|
9
|
+
|
10
|
+
First, a version object will return the string representation
|
11
|
+
via #to_s.
|
12
|
+
|
13
|
+
v = Library::Version.new('1.2.3')
|
14
|
+
'1.2.3'.assert == v.to_s
|
15
|
+
|
16
|
+
It will also do this for #to_str.
|
17
|
+
|
18
|
+
v = Library::Version.new('1.2.3')
|
19
|
+
'1.2.3'.assert == v.to_str
|
20
|
+
|
21
|
+
The actual segments of a version are stored in an array.
|
22
|
+
We can access those via #[].
|
23
|
+
|
24
|
+
v = Library::Version.new('1.2.3')
|
25
|
+
1.assert == v[0]
|
26
|
+
2.assert == v[1]
|
27
|
+
3.assert == v[2]
|
28
|
+
|
29
|
+
In addition certain segmetns have special names.
|
30
|
+
The first is accessible via #major.
|
31
|
+
|
32
|
+
v = Library::Version.new('1.2.3')
|
33
|
+
v.major.assert == 1
|
34
|
+
|
35
|
+
The second is accessible via #minor.
|
36
|
+
|
37
|
+
v = Library::Version.new('1.2.3')
|
38
|
+
v.minor.assert == 2
|
39
|
+
|
40
|
+
The third is accessible via #patch.
|
41
|
+
|
42
|
+
v = Library::Version.new('1.2.3')
|
43
|
+
v.patch.assert == 3
|
44
|
+
|
45
|
+
And lastly anything beyond the patch number is accessible
|
46
|
+
via #build.
|
47
|
+
|
48
|
+
v = Library::Version.new('1.2.3.pre.1')
|
49
|
+
v.build.assert == 'pre.1'
|
50
|
+
|
51
|
+
Two version can be compared with the #<=> method, which
|
52
|
+
importantly also makes lists of versions sortable.
|
53
|
+
|
54
|
+
v1 = Library::Version.new('1.2.3')
|
55
|
+
v2 = Library::Version.new('1.2.4')
|
56
|
+
(v2 <=> v1).assert == 1
|
57
|
+
|
58
|
+
While #=~ provides *pessimistic* constraint comparison.
|
59
|
+
|
60
|
+
v1 = Library::Version.new('1.2.4')
|
61
|
+
v2 = Library::Version.new('1.2')
|
62
|
+
assert(v1 =~ v2)
|
63
|
+
|
64
|
+
The Version class also provides some useful singleton methods
|
65
|
+
such as #parse_constraint. This method deciphers a comparision string.
|
66
|
+
|
67
|
+
a = Library::Version.parse_constraint("~> 1.0.0")
|
68
|
+
e = ["=~", Library::Version['1.0.0']]
|
69
|
+
a.assert == e
|
70
|
+
|
71
|
+
Equality can be written with `==` or `=`.
|
72
|
+
|
73
|
+
a = Library::Version.parse_constraint("= 0.9.0")
|
74
|
+
e = ["==", Library::Version['0.9.0']]
|
75
|
+
a.assert == e
|
76
|
+
|
77
|
+
Without an operator equality is implied.
|
78
|
+
|
79
|
+
a = Library::Version.parse_constraint("1.1")
|
80
|
+
e = [ "==", Library::Version['1.1'] ]
|
81
|
+
a.assert == e
|
82
|
+
|
83
|
+
This is usefuly for parsing requirement configurations. Using it, the Version
|
84
|
+
class can build contraint comparison procedures.
|
85
|
+
|
86
|
+
compare = Library::Version.constraint_lambda("=1.0")
|
87
|
+
compare.call('1.0').assert == true
|
88
|
+
compare.call('0.9').assert == false
|
89
|
+
|
90
|
+
Greater than
|
91
|
+
|
92
|
+
compare = Library::Version.constraint_lambda(">1.0")
|
93
|
+
compare.call('1.1').assert == true
|
94
|
+
compare.call('0.9').assert == false
|
95
|
+
|
96
|
+
Less than
|
97
|
+
|
98
|
+
compare = Library::Version.constraint_lambda("<1.0")
|
99
|
+
compare.call('1.1').assert == false
|
100
|
+
compare.call('0.9').assert == true
|
101
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
if ENV['RUBYOPT'].index('-rubylibs') || ENV['RUBYOPT'].index('-roll')
|
2
|
+
abort "Remove -rubylibs or -roll from RUBYOPT before running these tests."
|
3
|
+
end
|
4
|
+
|
5
|
+
# Make sure we use local version of files.
|
6
|
+
#$:.unshift('lib')
|
7
|
+
|
8
|
+
def fixtures
|
9
|
+
@_fixtures ||= File.dirname(__FILE__) + '/../fixtures'
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'library'
|
2
|
+
require 'library/kernel'
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
project_directory = Pathname.new('projects')
|
7
|
+
|
8
|
+
When 'Given a project directory "(((\S+)))"' do |name|
|
9
|
+
@project_directory = project_directory + name
|
10
|
+
libdir = @project_directory + 'lib'
|
11
|
+
FileUtils.mkdir_p(libdir) unless libdir.exist?
|
12
|
+
end
|
13
|
+
|
14
|
+
When 'With a file "(((\S+)))" containing' do |name, text|
|
15
|
+
file = @project_directory + name
|
16
|
+
FileUtils.mkdir_p(file.parent) unless file.parent.exist?
|
17
|
+
File.open(file.to_s, 'w'){ |f| f << text }
|
18
|
+
end
|
19
|
+
|
20
|
+
Before :demo do
|
21
|
+
prime_ledger
|
22
|
+
#p $LEDGER
|
23
|
+
end
|
24
|
+
|
25
|
+
# Support method to setup fresh Ledger.
|
26
|
+
def prime_ledger
|
27
|
+
projects = File.dirname(__FILE__) + '/../fixtures/*'
|
28
|
+
|
29
|
+
# reset ledger (shouldn't this happen in Library.prime call?)
|
30
|
+
$LEDGER = ::Library::Ledger.new
|
31
|
+
|
32
|
+
::Library.prime(*projects, :expound=>true)
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
$foo_message = "Foo 0.8.2"
|
@@ -0,0 +1 @@
|
|
1
|
+
$tryme_message = "Try Me v1.0"
|
@@ -0,0 +1 @@
|
|
1
|
+
$tryme_message = "Try Me v1.1"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
= Additional Project
|
2
|
+
|
3
|
+
== Neo 0.0.1
|
4
|
+
|
5
|
+
Given a project directory "neo/0.0.1".
|
6
|
+
|
7
|
+
With a file "VERSION" containing...
|
8
|
+
|
9
|
+
name: neo
|
10
|
+
vers: 0.0.1
|
11
|
+
|
12
|
+
With a file "PROFILE" containing...
|
13
|
+
|
14
|
+
title : Neo
|
15
|
+
author : Thomas Sawyer
|
16
|
+
homepage: http://neo.foo
|
17
|
+
|
18
|
+
With a file "lib/neo.rb" containing...
|
19
|
+
|
20
|
+
$neo_message = "Neo v0.0.1"
|
21
|
+
|
22
|
+
With a file ".ruby/name" containing...
|
23
|
+
|
24
|
+
neo
|
25
|
+
|
26
|
+
With a file ".ruby/version" containing...
|
27
|
+
|
28
|
+
0.0.1
|
29
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
= Basic Set of Projects
|
2
|
+
|
3
|
+
== TryMe 1.0
|
4
|
+
|
5
|
+
Given a project directory "tryme/1.0".
|
6
|
+
|
7
|
+
With a file "VERSION" containing...
|
8
|
+
|
9
|
+
name: tryme
|
10
|
+
vers: 1.0
|
11
|
+
|
12
|
+
With a file "PROFILE" containing...
|
13
|
+
|
14
|
+
title : TryMe
|
15
|
+
author : Thomas Sawyer
|
16
|
+
homepage: http://tryme.foo
|
17
|
+
|
18
|
+
With a file "lib/tryme.rb" containing...
|
19
|
+
|
20
|
+
$tryme_message = "Try Me v1.0"
|
21
|
+
|
22
|
+
With a file ".ruby/name" containing...
|
23
|
+
|
24
|
+
tryme
|
25
|
+
|
26
|
+
With a file ".ruby/version" containing...
|
27
|
+
|
28
|
+
1.0
|
29
|
+
|
30
|
+
== TryMe 1.1
|
31
|
+
|
32
|
+
Given a project directory "tryme/1.1".
|
33
|
+
|
34
|
+
With a file "VERSION" containing...
|
35
|
+
|
36
|
+
name: tryme
|
37
|
+
vers: 1.1
|
38
|
+
|
39
|
+
With a file "PROFILE" containing...
|
40
|
+
|
41
|
+
title : TryMe
|
42
|
+
author : Thomas Sawyer
|
43
|
+
homepage: http://tryme.foo
|
44
|
+
|
45
|
+
With a file "lib/tryme.rb" containing...
|
46
|
+
|
47
|
+
$tryme_message = "Try Me v1.1"
|
48
|
+
|
49
|
+
With a file ".ruby/name" containing...
|
50
|
+
|
51
|
+
tryme
|
52
|
+
|
53
|
+
With a file ".ruby/version" containing...
|
54
|
+
|
55
|
+
1.1
|
56
|
+
|
data/test/case_ledger.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
covers 'library/ledger'
|
2
|
+
|
3
|
+
testcase Library::Ledger do
|
4
|
+
|
5
|
+
method :add do
|
6
|
+
test do
|
7
|
+
ledger = Library::Ledger.new
|
8
|
+
ledger.add(File.dirname(__FILE__) + '/fixture')
|
9
|
+
ledger.assert.size == 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
method :[] do
|
14
|
+
test do
|
15
|
+
ledger = Library::Ledger.new
|
16
|
+
ledger.add(File.dirname(__FILE__) + '/fixture')
|
17
|
+
|
18
|
+
ledger[:foo].assert.is_a? Array
|
19
|
+
ledger['foo'].assert.is_a? Array
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
covers 'library/version'
|
2
|
+
|
3
|
+
testcase Library::Version do
|
4
|
+
|
5
|
+
concern "Ensure functionality of Roll's Version class."
|
6
|
+
|
7
|
+
method :to_s do
|
8
|
+
test do
|
9
|
+
v = Library::Version.new('1.2.3')
|
10
|
+
v.to_s.assert == '1.2.3'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
method :to_str do
|
15
|
+
test do
|
16
|
+
v = Library::Version.new('1.2.3')
|
17
|
+
v.to_str.assert == '1.2.3'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
method :inspect do
|
22
|
+
test do
|
23
|
+
v = Library::Version.new('1.2.3')
|
24
|
+
v.inspect.assert == '1.2.3'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
method :[] do
|
29
|
+
test do
|
30
|
+
v = Library::Version.new('1.2.3')
|
31
|
+
v[0].assert == 1
|
32
|
+
v[1].assert == 2
|
33
|
+
v[2].assert == 3
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
method :<=> do
|
38
|
+
test do
|
39
|
+
v1 = Library::Version.new('1.2.3')
|
40
|
+
v2 = Library::Version.new('1.2.4')
|
41
|
+
(v2 <=> v1).assert == 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# TODO
|
46
|
+
# def =~( other )
|
47
|
+
# #other = other.to_t
|
48
|
+
# upver = other.dup
|
49
|
+
# upver[0] += 1
|
50
|
+
# @self >= other and @self < upver
|
51
|
+
# end
|
52
|
+
|
53
|
+
method :=~ do
|
54
|
+
test "pessimistic constraint" do
|
55
|
+
v1 = Library::Version.new('1.2.4')
|
56
|
+
v2 = Library::Version.new('1.2')
|
57
|
+
assert(v1 =~ v2)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
method :major do
|
62
|
+
test do
|
63
|
+
v = Library::Version.new('1.2.3')
|
64
|
+
v.major.assert == 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
method :minor do
|
69
|
+
test do
|
70
|
+
v = Library::Version.new('1.2.3')
|
71
|
+
v.minor.assert == 2
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
method :patch do
|
76
|
+
test do
|
77
|
+
v = Library::Version.new('1.2.3')
|
78
|
+
v.patch.assert == 3
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class_method :parse_constraint do
|
83
|
+
test do
|
84
|
+
constraint = Library::Version.parse_constraint("~> 1.0.0")
|
85
|
+
constraint.assert == ["=~", Library::Version['1.0.0']]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|