roll 0.8.0 → 1.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.
Files changed (63) hide show
  1. data/{LICENSE → COPYING} +1 -1
  2. data/HISTORY +62 -0
  3. data/README.rdoc +169 -0
  4. data/TODO +4 -0
  5. data/bin/roll +3 -44
  6. data/lib/oll.rb +1 -2
  7. data/lib/roll.rb +87 -0
  8. data/lib/roll/command.rb +207 -0
  9. data/lib/roll/config.rb +80 -0
  10. data/lib/roll/environment.rb +317 -0
  11. data/lib/roll/errors.rb +13 -0
  12. data/lib/roll/kernel.rb +41 -0
  13. data/lib/roll/ledger.rb +299 -0
  14. data/lib/roll/library.rb +241 -558
  15. data/lib/roll/locals.rb +96 -0
  16. data/lib/roll/metadata.rb +112 -0
  17. data/lib/roll/original.rb +10 -0
  18. data/lib/roll/version.rb +91 -101
  19. data/meta/active +1 -0
  20. data/meta/authors +1 -0
  21. data/meta/contact +1 -0
  22. data/meta/created +1 -0
  23. data/meta/description +5 -0
  24. data/meta/homepage +1 -0
  25. data/meta/maintainer +1 -0
  26. data/meta/name +1 -0
  27. data/meta/repository +1 -0
  28. data/meta/ruby +2 -0
  29. data/meta/suite +1 -0
  30. data/meta/summary +1 -0
  31. data/meta/version +1 -0
  32. data/script/rdoc +4 -0
  33. data/script/setup +1344 -0
  34. data/script/test +23 -0
  35. data/test/benchmarks/vsgems.rb +11 -0
  36. data/test/benchmarks/vsgems_bm.rb +17 -0
  37. data/test/demonstrations/01_library.rdoc +33 -0
  38. data/test/demonstrations/04_version.rdoc +56 -0
  39. data/test/fixtures/env.list +1 -0
  40. data/{demo/sample → test/fixtures}/inspect.rb +0 -0
  41. data/test/fixtures/tryme/1.0/lib/tryme.rb +1 -0
  42. data/test/fixtures/tryme/1.0/meta/homepage +1 -0
  43. data/test/fixtures/tryme/1.0/meta/name +1 -0
  44. data/test/fixtures/tryme/1.0/meta/version +1 -0
  45. data/test/fixtures/tryme/1.1/lib/tryme.rb +1 -0
  46. data/test/fixtures/tryme/1.1/meta/homepage +1 -0
  47. data/test/fixtures/tryme/1.1/meta/name +1 -0
  48. data/test/fixtures/tryme/1.1/meta/version +1 -0
  49. data/test/{test_version.rb → unit/version_test.rb} +21 -21
  50. data/test/unitcases/version_case.rb +69 -0
  51. metadata +102 -65
  52. data/README +0 -17
  53. data/demo/bench/bench_load.rb +0 -7
  54. data/demo/sample/tryme/1.0/lib/tryme.rb +0 -1
  55. data/demo/sample/tryme/1.1/lib/tryme.rb +0 -1
  56. data/lib/roll/attributes.rb +0 -72
  57. data/lib/roll/package.rb +0 -300
  58. data/lib/roll/remote.rb +0 -37
  59. data/meta/ROLL-0.8.0.roll +0 -21
  60. data/task/rdoc +0 -9
  61. data/task/setup +0 -1616
  62. data/task/test +0 -5
  63. data/test/test_library.rb +0 -10
@@ -0,0 +1,80 @@
1
+ require 'rbconfig'
2
+
3
+ module ::Config
4
+
5
+ HOME = File.expand_path('~') # ENV['HOME']
6
+
7
+ # Location of user's personal config directory.
8
+ CONFIG_HOME = File.expand_path(ENV['XDG_CONFIG_HOME'] || File.join(HOME, '.config'))
9
+
10
+ # List of user shared system config directories.
11
+ CONFIG_DIRS = (
12
+ dirs = ENV['XDG_CONFIG_DIRS'].to_s.split(/[:;]/)
13
+ if dirs.empty?
14
+ dirs = File.join(Config::CONFIG['sysconfdir'], 'xdg')
15
+ end
16
+ dirs.collect{ |d| File.expand_path(d) }
17
+ )
18
+
19
+ WIN_PATTERNS = [
20
+ /bccwin/i,
21
+ /cygwin/i,
22
+ /djgpp/i,
23
+ /mingw/i,
24
+ /mswin/i,
25
+ /wince/i,
26
+ ]
27
+
28
+ # Is this a windows platform?
29
+ def self.win_platform?
30
+ @win_platform ||= (
31
+ !!WIN_PATTERNS.find{ |r| RUBY_PLATFORM =~ r }
32
+ )
33
+ end
34
+
35
+ # Return the path to the data directory associated with the given
36
+ # library name.
37
+ #--
38
+ #Normally this is just
39
+ # "#{Config::CONFIG['datadir']}/#{name}", but may be
40
+ # modified by packages like RubyGems and Rolls to handle
41
+ # versioned data directories.
42
+ #++
43
+
44
+ def self.datadir(name, versionless=false)
45
+ if lib = Roll::Library.instance(name)
46
+ lib.datadir(versionless)
47
+ else
48
+ File.join(CONFIG['datadir'], name)
49
+ end
50
+ end
51
+
52
+ # Return the path to the configuration directory.
53
+
54
+ def self.confdir(name)
55
+ if lib = Roll::Library.instance(name)
56
+ lib.confdir
57
+ else
58
+ File.join(CONFIG['confdir'], name)
59
+ end
60
+ end
61
+
62
+ # Lookup configuration file.
63
+
64
+ def self.find_config(*glob)
65
+ flag = 0
66
+ flag = (flag | glob.pop) while Fixnum === glob.last
67
+ find = []
68
+ [CONFIG_HOME, *CONFIG_DIRS].each do |dir|
69
+ path = File.join(dir, *glob)
70
+ if block_given?
71
+ find.concat(Dir.glob(path, flag).select(&block))
72
+ else
73
+ find.concat(Dir.glob(path, flag))
74
+ end
75
+ end
76
+ find
77
+ end
78
+
79
+ end
80
+
@@ -0,0 +1,317 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+ #require 'roll/xdg'
4
+ require 'roll/config'
5
+
6
+ module Roll
7
+
8
+ # An Environment represents a set of libraries.
9
+ #
10
+ class Environment
11
+
12
+ # Default environment name.
13
+ DEFAULT = 'production' # 'local' ?
14
+
15
+ # Location of environment files.
16
+ #--
17
+ # Perhaps combine all enrtries instead?
18
+ #++
19
+ DIRS = ::Config.find_config('roll')
20
+
21
+ # Current environment name.
22
+ def self.current
23
+ ENV['RUBYENV'] || DEFAULT
24
+ end
25
+
26
+ # List of available environments.
27
+ def self.list
28
+ Dir[File.join(DIR, '*')].map do |file|
29
+ File.basename(file)
30
+ end
31
+ end
32
+
33
+ # Environment name.
34
+ attr :name
35
+
36
+ # Instantiate environment.
37
+ def initialize(name=nil)
38
+ @name = name || Environment.current
39
+ end
40
+
41
+ #
42
+ def index
43
+ @index ||= Index.new(name)
44
+ end
45
+
46
+ #
47
+ def lookup
48
+ @lookup ||= Lookup.new(name)
49
+ end
50
+
51
+ # Synchronize index to lookup table.
52
+ def sync
53
+ index.reset(lookup.index)
54
+ end
55
+
56
+ # Save index.
57
+ def save
58
+ index.save
59
+ end
60
+
61
+ #
62
+ def each(&block) ; index.each(&block) ; end
63
+
64
+ #
65
+ def size ; index.size ; end
66
+
67
+ #
68
+ def to_s
69
+ str = ""
70
+ lookup.each do |(path, depth)|
71
+ str << "#{path} #{depth}\n"
72
+ end
73
+ str
74
+ end
75
+
76
+
77
+ # Index tracks the name and location of each library
78
+ # in an environment.
79
+ #--
80
+ # TODO: Using a hash table means un-order, fix?
81
+ #++
82
+ class Index
83
+ include Enumerable
84
+
85
+ # Instantiate environment.
86
+ def initialize(name=nil)
87
+ @name = name || Environment.current
88
+ @table = Hash.new{ |h,k| h[k] = [] }
89
+ reload
90
+ end
91
+
92
+ # Current ledger name.
93
+ def name
94
+ @name
95
+ end
96
+
97
+ # Environment file (full-path).
98
+ def file
99
+ @file ||= ::Config.find_config('roll', name, 'index').first
100
+ end
101
+
102
+ # Load the environment file.
103
+ def reload
104
+ if file && File.exist?(file)
105
+ File.readlines(file).each do |line|
106
+ line = line.strip
107
+ next if line.empty?
108
+ name, path = *line.split(/\s+/)
109
+ @table[name.strip] << path.strip
110
+ end
111
+ end
112
+ end
113
+
114
+ #
115
+ def reset(index)
116
+ @table = index
117
+ end
118
+
119
+ # Look through the environment table.
120
+ def each(&block)
121
+ @table.each(&block)
122
+ end
123
+
124
+ # Number of entries.
125
+ def size
126
+ @table.size
127
+ end
128
+
129
+ #
130
+ def to_h
131
+ @table.dup
132
+ end
133
+
134
+ #
135
+ def to_s
136
+ out = ""
137
+ max = @table.map{ |name, paths| name.size }.max
138
+ @table.map do |name, paths|
139
+ paths.each do |path|
140
+ out << "%-#{max}s %s\n" % [name, path]
141
+ end
142
+ end
143
+ out
144
+ end
145
+
146
+ # Save environment file.
147
+ def save
148
+ out = to_s
149
+ #max = @table.map{ |name, paths| name.size }.max
150
+ #@table.map do |name, paths|
151
+ # paths.each do |path|
152
+ # out << "%-#{max}s %s\n" % [name, path]
153
+ # end
154
+ #end
155
+ file = File.join(::Config::CONFIG_HOME, 'roll', name, 'index')
156
+ if File.exist?(file)
157
+ data = File.read(file)
158
+ if out != data
159
+ File.open(file, 'w'){ |f| f << out }
160
+ #puts "updated: #{name}"
161
+ true
162
+ else
163
+ #puts "current: #{name}"
164
+ false
165
+ end
166
+ else
167
+ dir = File.dirname(file)
168
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
169
+ File.open(file, 'w'){ |f| f << out }
170
+ #puts "created: #{name}"
171
+ true
172
+ end
173
+ @file = file
174
+ end
175
+
176
+ =begin
177
+ # Get library version.
178
+ # TODO: handle VERSION file
179
+ def load_version(path)
180
+ file = Dir[File.join(path, '{,.}meta', 'version')].first
181
+ if file
182
+ File.read(file).strip # TODO: handle YAML ?
183
+ end
184
+ end
185
+ =end
186
+
187
+ end
188
+
189
+ # The Lookup class provides a table of paths which
190
+ # make it easy to quickly populate and refresh the
191
+ # environment index.
192
+
193
+ class Lookup
194
+ include Enumerable
195
+
196
+ #
197
+ #DIR = ::Config.find_config('roll').first
198
+
199
+ #
200
+ def initialize(name=nil)
201
+ @name = name || Environment.current
202
+ reload
203
+ end
204
+
205
+ #
206
+ def name
207
+ @name
208
+ end
209
+
210
+ #
211
+ def file
212
+ @file ||= ::Config.find_config('roll', name, 'lookup').first
213
+ end
214
+
215
+ #
216
+ def reload
217
+ t = []
218
+ if file && File.exist?(file)
219
+ lines = File.readlines(file)
220
+ lines.each do |line|
221
+ line = line.strip
222
+ path, depth = *line.split(/\s+/)
223
+ next if line =~ /^\s*$/ # blank
224
+ next if line =~ /^\#/ # comment
225
+ dir, depth = *line.split(/\s+/)
226
+ t << [path, (depth || 3).to_i]
227
+ end
228
+ else
229
+ t = []
230
+ end
231
+ @table = t
232
+ end
233
+
234
+ #
235
+ def each(&block)
236
+ @table.each(&block)
237
+ end
238
+
239
+ #
240
+ def size
241
+ @table.size
242
+ end
243
+
244
+ #
245
+ def append(path, depth=3)
246
+ path = File.expand_path(path)
247
+ depth = (depth || 3).to_i
248
+ @table = @table.reject{ |(p, d)| path == p }
249
+ @table.push([path, depth])
250
+ end
251
+
252
+ #
253
+ def delete(path)
254
+ @table.reject!{ |p,d| path == p }
255
+ end
256
+
257
+ #
258
+ def save
259
+ file = File.join(::Config::CONFIG_HOME, 'roll', name, 'lookup')
260
+ out = @table.map do |(path, depth)|
261
+ "#{path} #{depth}"
262
+ end
263
+ dir = File.dirname(file)
264
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
265
+ File.open(file, 'w') do |f|
266
+ f << out.join("\n")
267
+ end
268
+ @file = file
269
+ end
270
+
271
+ # Generate index from lookup list.
272
+ def index
273
+ set = Hash.new{ |h,k| h[k] = [] }
274
+ locate.each do |path|
275
+ name = load_name(path)
276
+ #vers = load_version(path)
277
+ if name #&& vers
278
+ set[name] << path
279
+ end
280
+ end
281
+ set
282
+ end
283
+
284
+ #
285
+ def locate
286
+ locs = []
287
+ each do |dir, depth|
288
+ locs << find_projects(dir, depth)
289
+ end
290
+ locs.flatten
291
+ end
292
+
293
+ # Search a given directory for projects upto a given depth.
294
+ # Projects directories are determined by containing a
295
+ # 'meta' or '.meta' directory.
296
+ def find_projects(dir, depth=3)
297
+ depth = Integer(depth || 3)
298
+ depth = (0...depth).map{ |i| (["*"] * i).join('/') }.join(',')
299
+ glob = File.join(dir, "{#{depth}}", "{.meta,meta}")
300
+ meta_locations = Dir[glob]
301
+ meta_locations.map{ |d| d.chomp('/meta').chomp('/.meta') }
302
+ end
303
+
304
+ # Get library name.
305
+ def load_name(path)
306
+ file = Dir[File.join(path, '{,.}meta', 'name')].first
307
+ if file
308
+ File.read(file).strip # TODO: handle YAML
309
+ end
310
+ end
311
+
312
+ end#class Lookup
313
+
314
+ end#class Environment
315
+
316
+ end
317
+
@@ -0,0 +1,13 @@
1
+ module Roll
2
+
3
+ # VersionError is raised when a requested version cannot be found.
4
+ class VersionError < ::RangeError # :nodoc:
5
+ end
6
+
7
+ # VersionConflict is raised when selecting another version
8
+ # of a library when a previous version has already been selected.
9
+ class VersionConflict < ::LoadError # :nodoc:
10
+ end
11
+
12
+ end
13
+
@@ -0,0 +1,41 @@
1
+ require 'roll/original'
2
+ require 'roll/ledger'
3
+
4
+ module ::Kernel
5
+
6
+ # In which library is the current file participating?
7
+ def __LIBRARY__
8
+ Roll::Library.load_stack.last
9
+ end
10
+
11
+ # Activate a library.
12
+ def library(name, constraint=nil)
13
+ Roll::Library.open(name, constraint)
14
+ end
15
+
16
+ module_function :library
17
+
18
+ # Activate a library.
19
+ def roll(name, constraint=nil)
20
+ Roll::Library.open(name, constraint)
21
+ end
22
+
23
+ module_function :roll
24
+
25
+ # Require script.
26
+ def require(file)
27
+ Roll::Library.require(file)
28
+ end
29
+
30
+ # Load script.
31
+ def load(file, wrap=false)
32
+ Roll::Library.load(file, wrap)
33
+ end
34
+
35
+ # Acquire script.
36
+ def acquire(file, opts={})
37
+ Roll::Library.acquire(file, opts)
38
+ end
39
+
40
+ end
41
+