bezel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY ADDED
@@ -0,0 +1,12 @@
1
+ = Release History
2
+
3
+ == 0.1.0 / 2010-02-19
4
+
5
+ This is an alpha release of Bezel, an alternate load
6
+ system for Ruby, just to put it out there and get
7
+ some feedback.
8
+
9
+ Changes:
10
+
11
+ * Happy Frakn Birthday!
12
+
@@ -0,0 +1,25 @@
1
+ HISTORY
2
+ MANIFEST
3
+ README
4
+ lib/bezel.rb
5
+ meta/homepage
6
+ meta/name
7
+ meta/ruby
8
+ meta/suite
9
+ meta/summary
10
+ meta/title
11
+ meta/version
12
+ test/demos
13
+ test/demos/01_example.rdoc
14
+ test/fixtures
15
+ test/fixtures/gems
16
+ test/fixtures/gems/tryme-1.0
17
+ test/fixtures/gems/tryme-1.0/lib
18
+ test/fixtures/gems/tryme-1.0/lib/tryme
19
+ test/fixtures/gems/tryme-1.0/lib/tryme.rb
20
+ test/fixtures/gems/tryme-1.0/lib/tryme/extra.rb
21
+ test/fixtures/gems/tryme-1.1
22
+ test/fixtures/gems/tryme-1.1/lib
23
+ test/fixtures/gems/tryme-1.1/lib/tryme
24
+ test/fixtures/gems/tryme-1.1/lib/tryme.rb
25
+ test/fixtures/gems/tryme-1.1/lib/tryme/extra.rb
data/README ADDED
@@ -0,0 +1,60 @@
1
+ = Bezel
2
+
3
+ * home: http://proutils.github.com/bezel
4
+ * work: http://github.com/proutils/bezel
5
+
6
+ == DESCRIPTION
7
+
8
+ The idea of Bezel is to overcome the limitations of using different
9
+ versions of the same package in the same Ruby process.
10
+
11
+ == USAGE
12
+
13
+ It works like this. Let's say I wrote a library called TomsLib. Now I
14
+ want to use TomsLib in my new fancy app, FancyApp. In my FancyApp
15
+ namespace I have to create a reference to TomsLib.
16
+
17
+ module FancyApp
18
+ TomsLib = lib('tomslib', '1.5')
19
+ ...
20
+
21
+ Now I have access to TomsLib, but it is localized to my application.
22
+ If Jane comes along and wants to use a different version of TomsLib
23
+ but also utilizes my FancyApp, she could do so:
24
+
25
+ module JanesProgram
26
+ TomsLib = lib('tomslib', '1.0')
27
+ FancyApp = lib('fancyapp') # use newest available
28
+ ...
29
+
30
+ How does this work? When you call lib(), Bezel looks for the package
31
+ in the current Gem paths (and in the future, Roll ledger) then it
32
+ reads the primary package file (eg. tomslib.rb) from the package and
33
+ evals it into an anonymous module.
34
+
35
+ This has a some important effects on how you write your Ruby programs:
36
+
37
+ 1. Any reference to core/standard libraries must be referenced via '::'
38
+ prefix (eg. ::Enumerable).
39
+
40
+ 2. Core extensions are not version isolated. So avoid them when
41
+ possible, or depend on highly stable standardized bases such as
42
+ Ruby Facets and ActiveSupport.
43
+
44
+ 3. Since Bezel is a completely different alternative to Ruby's normal
45
+ load system, your program will require Bezel be installed by your
46
+ users.
47
+
48
+ 4. Within Bezel dependent libraries #import must be used instead of
49
+ #require or #load in order to keep the code within the current module.
50
+
51
+ Despite the minor limitations and necessary practices required for its
52
+ use, Bezel is highly advantageous to the developers and end-users alike
53
+ in that it puts an end to the dreaded Dependency Hell.
54
+
55
+ == COPYRIGHT
56
+
57
+ Copyright (c) 2009 Thomas Sawyer
58
+
59
+ Bezel is distributed under the terms of the Ruby License.
60
+
@@ -0,0 +1,130 @@
1
+ # The idea of Bezel is to overcome the limitations of using
2
+ # different versions of the same package in the same Ruby
3
+ # proccess.
4
+ #
5
+ # It works like this. Let's say I wrote a library called TomsLib.
6
+ # Now I want to use TomsLib in my new fancy app, FancyApp. In my
7
+ # FancyApp namespace I have to create a reference to TomsLib.
8
+ #
9
+ # module FancyApp
10
+ # TomsLib = lib('tomslib', '1.5')
11
+ # ...
12
+ #
13
+ # Now I have access to TomsLib, but it is localized to my
14
+ # application. If Jane comes along and wants to use a different
15
+ # version of TomsLib but also utilizes my FancyApp, she
16
+ # could do so:
17
+ #
18
+ # module JanesProgram
19
+ # TomsLib = lib('tomslib', '1.0')
20
+ # FancyApp = lib('fancyapp') # use newest available
21
+ # ...
22
+ #
23
+ # How does this work? When you call library(), Bezel looks for
24
+ # the package in the current gem paths (and, in the future, Roll ledger)
25
+ # then it reads the primary package file (eg. tomslib.rb) fro the package
26
+ # and evals it into an anonymous module.
27
+ #
28
+ # This has a some important effects on how you write your Ruby programs:
29
+ #
30
+ # 1. Any reference to core/standard libraries must be referenced via
31
+ # :: prefix (eg. ::Enumerable).
32
+ #
33
+ # 2. Core extensions are not version controlled. So avoid them when
34
+ # possible, or depend on highly stable standardized bases such as
35
+ # Facets and ActiveSupport.
36
+ #
37
+ # 3. Since Bezel is a completely different alternative to Ruby's normal
38
+ # load system, your program will require Bezel be installed by your
39
+ # users.
40
+ #
41
+ # Despite the limitations and necessary practices required for its use
42
+ # Bezel is highly advantageous to the developers and end-users alike
43
+ # in that it puts an end to the dreaded Dependency Hell.
44
+ #
45
+ class Bezel < Module
46
+ require 'rubygems'
47
+
48
+ # Cache of loaded modules. This speeds things
49
+ # up if two libraries load the same third library.
50
+ TABLE = Hash.new{|h,k|h[k]={}}
51
+
52
+ # Load stack keeps track of what modules are in the process
53
+ # of being loaded.
54
+ STACK = []
55
+
56
+ #
57
+ def self.gem_paths
58
+ @gem_paths ||= (
59
+ Gem.path.map do |dir|
60
+ Dir[File.join(dir, 'gems', '*')]
61
+ end.flatten
62
+ )
63
+ end
64
+
65
+ #
66
+ def self.select(name)
67
+ gem_paths.select do |path|
68
+ File.basename(path) =~ /^#{name}-/
69
+ end
70
+ end
71
+
72
+ #
73
+ def self.find(name, version=nil)
74
+ if version
75
+ basename = "#{name}-#{version}"
76
+ select(name).find do |path|
77
+ File.basename(path) == basename
78
+ end
79
+ else
80
+ select(name).max
81
+ end
82
+ end
83
+
84
+ #
85
+ #def self.main(name, version=nil)
86
+ # path = find(name, version)
87
+ # File.join(path, 'lib', name + '.rb')
88
+ #end
89
+
90
+ #
91
+ def initialize(name, path)
92
+ @__name__ = name
93
+ @__path__ = path
94
+ end
95
+
96
+ def __name__
97
+ @__name__
98
+ end
99
+
100
+ def __path__
101
+ @__path__
102
+ end
103
+
104
+ end
105
+
106
+ #
107
+ def lib(name, version=nil)
108
+ path = Bezel.find(name, version)
109
+ main = File.join(path, 'lib', name + '.rb')
110
+
111
+ return Bezel::TABLE[main] if Bezel::TABLE.key?(main)
112
+
113
+ mod = Bezel.new(name, path)
114
+
115
+ Bezel::STACK << mod
116
+
117
+ mod.module_eval(File.read(main), main, 0)
118
+
119
+ Bezel::STACK.pop
120
+
121
+ Bezel::TABLE[main] = mod
122
+ end
123
+
124
+ # When using Bezel, rather than use #require or #load, you use #import.
125
+ def import(fname)
126
+ mod = Bezel::STACK.last
127
+ file = File.join(mod.__path__, 'lib', mod.__name__, fname)
128
+ mod.module_eval(File.read(file), file, 0)
129
+ end
130
+
@@ -0,0 +1 @@
1
+ http://proutils.github.com/bezel
@@ -0,0 +1 @@
1
+ bezel
@@ -0,0 +1 @@
1
+ 1.8.7
@@ -0,0 +1 @@
1
+ proutils
@@ -0,0 +1 @@
1
+ Alternate loading system for Ruby allowing version multiplicity.
@@ -0,0 +1 @@
1
+ Bezel
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,46 @@
1
+ = Bezel
2
+
3
+ First Bezel must be loaded, of course. This will also load
4
+ RubyGems as Bezel presently uses the +Gem.path+ to locate
5
+ Ruby libraries.
6
+
7
+ require 'bezel'
8
+
9
+ We are going to use a dummy Gem location for this example.
10
+
11
+ Gem.path.unshift(File.expand_path('../fixtures'))
12
+
13
+ Now we can try it out. The dummy location houses two libraries
14
+ of the same name but different versions.
15
+
16
+ module Example1
17
+ TryMe = lib('tryme', '1.0')
18
+ end
19
+
20
+ TryMe has a class method called #report and we should see that
21
+ it works as expected.
22
+
23
+ Example1::TryMe.report.assert == "You are using version 1.0!"
24
+
25
+ It also imports a method called #extra from a seperate file.
26
+
27
+ Example1::TryMe.extra.assert == "Something extra from version 1.0!"
28
+
29
+ Now we should be able to do the same for TryMe v1.1 without any
30
+ issues of interference betwee the two versions.
31
+
32
+ module Example2
33
+ TryMe = lib('tryme', '1.1')
34
+ end
35
+
36
+ Again we should see that the #report method works as expected, but this
37
+ time reported form the new version.
38
+
39
+ Example2::TryMe.report.assert == "You are using version 1.1!"
40
+
41
+ And that it also imports a method called #extra from a seperate file.
42
+
43
+ Example2::TryMe.extra.assert == "Something extra from version 1.1!"
44
+
45
+ That's all folks!
46
+
@@ -0,0 +1,11 @@
1
+ # TryMe 1.0
2
+
3
+ VERSION = "1.0"
4
+
5
+ def self.report
6
+ "You are using version #{VERSION}!"
7
+ end
8
+
9
+ import("extra.rb")
10
+
11
+
@@ -0,0 +1,5 @@
1
+
2
+ def self.extra
3
+ "Something extra from version #{VERSION}!"
4
+ end
5
+
@@ -0,0 +1,10 @@
1
+ # TryMe 1.1
2
+
3
+ VERSION = "1.1"
4
+
5
+ def self.report
6
+ "You are using version #{VERSION}!"
7
+ end
8
+
9
+ import("extra.rb")
10
+
@@ -0,0 +1,5 @@
1
+
2
+ def self.extra
3
+ "Something extra from version #{VERSION}!"
4
+ end
5
+
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bezel
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors: []
12
+
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-02-19 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: ""
22
+ email:
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - HISTORY
31
+ - MANIFEST
32
+ - README
33
+ - lib/bezel.rb
34
+ - meta/homepage
35
+ - meta/name
36
+ - meta/ruby
37
+ - meta/suite
38
+ - meta/summary
39
+ - meta/title
40
+ - meta/version
41
+ - test/demos/01_example.rdoc
42
+ - test/fixtures/gems/tryme-1.0/lib/tryme.rb
43
+ - test/fixtures/gems/tryme-1.0/lib/tryme/extra.rb
44
+ - test/fixtures/gems/tryme-1.1/lib/tryme.rb
45
+ - test/fixtures/gems/tryme-1.1/lib/tryme/extra.rb
46
+ has_rdoc: true
47
+ homepage: http://proutils.github.com/bezel
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --title
53
+ - Bezel API
54
+ - --main
55
+ - README
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project: bezel
75
+ rubygems_version: 1.3.6.pre.3
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Alternate loading system for Ruby allowing version multiplicity.
79
+ test_files: []
80
+