main 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -372,6 +372,11 @@ DOCS
372
372
  API section below
373
373
 
374
374
  HISTORY
375
+ 2.7.0
376
+ - removed bundled arrayfields and attributes. these are now dependancies
377
+ mananged by rubygems. a.k.a. you must have rubygems installed for main
378
+ to work.
379
+
375
380
  2.6.0
376
381
  - added 'mixin' feaature for storing, and later evaluating a block of
377
382
  code. the purpose of this is for use with modes where you want to keep
data/gemspec.rb CHANGED
@@ -26,7 +26,7 @@ Gem::Specification::new do |spec|
26
26
  spec.has_rdoc = File::exist? "doc"
27
27
  spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
28
28
  spec.add_dependency 'attributes', '>= 5.0.0'
29
- spec.add_dependency 'arrayfields', '>= 4.3.0'
29
+ spec.add_dependency 'arrayfields', '>= 4.5.0'
30
30
 
31
31
  spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
32
32
 
data/lib/main.rb CHANGED
@@ -2,7 +2,7 @@ module Main
2
2
  #
3
3
  # top level constants
4
4
  #
5
- Main::VERSION = '2.6.0' unless
5
+ Main::VERSION = '2.7.0' unless
6
6
  defined? Main::VERSION
7
7
  def self.version() Main::VERSION end
8
8
 
@@ -20,25 +20,13 @@ module Main
20
20
  require 'enumerator'
21
21
  require 'set'
22
22
  #
23
- # we try to use gems to pick up dependancies
24
- #
25
- begin
26
- require 'rubygems'
27
- rescue LoadError
28
- 42
29
- end
30
- begin
31
- gem 'attributes', '~> 5.0.0'
32
- require 'attributes'
33
- rescue Exception
34
- require libdir + 'attributes'
35
- end
36
- begin
37
- gem 'arrayfields', '~> 4.3.0'
38
- require 'arrayfields'
39
- rescue Exception
40
- require libdir + 'arrayfields'
41
- end
23
+ # use gems to pick up dependancies
24
+ #
25
+ require 'rubygems'
26
+ gem 'attributes', '~> 5.0.0'
27
+ require 'attributes'
28
+ gem 'arrayfields', '~> 4.5.0'
29
+ require 'arrayfields'
42
30
  #
43
31
  # main's own libs
44
32
  #
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: main
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.6.0
7
- date: 2007-12-06 00:00:00 -07:00
6
+ version: 2.7.0
7
+ date: 2007-12-18 00:00:00 -07:00
8
8
  summary: main
9
9
  require_paths:
10
10
  - lib
@@ -35,8 +35,6 @@ files:
35
35
  - install.rb
36
36
  - lib
37
37
  - lib/main
38
- - lib/main/arrayfields.rb
39
- - lib/main/attributes.rb
40
38
  - lib/main/base.rb
41
39
  - lib/main/cast.rb
42
40
  - lib/main/factories.rb
@@ -44,7 +42,6 @@ files:
44
42
  - lib/main/logger.rb
45
43
  - lib/main/mode.rb
46
44
  - lib/main/parameter.rb
47
- - lib/main/pervasives.rb
48
45
  - lib/main/softspoken.rb
49
46
  - lib/main/stdext.rb
50
47
  - lib/main/usage.rb
@@ -91,5 +88,5 @@ dependencies:
91
88
  requirements:
92
89
  - - ">="
93
90
  - !ruby/object:Gem::Version
94
- version: 4.3.0
91
+ version: 4.5.0
95
92
  version:
@@ -1,434 +0,0 @@
1
- #
2
- # The ArrayFields module implements methods which allow an Array to be indexed
3
- # by String or Symbol. It is not required to manually use this module to
4
- # extend Arrays - they are auto-extended on a per-object basis when
5
- # Array#fields= is called
6
- #
7
- module ArrayFields
8
- self::VERSION = '4.5.0' unless defined? self::VERSION
9
- def self.version() VERSION end
10
- #
11
- # multiton cache of fields - wraps fields and fieldpos map to save memory
12
- #
13
- class FieldSet
14
- class << self
15
- def new fields
16
- @sets[fields] ||= super
17
- end
18
- def init_sets
19
- @sets = {}
20
- end
21
- end
22
-
23
- init_sets
24
-
25
- attr :fields
26
- attr :fieldpos
27
- def initialize fields
28
- raise ArgumentError, "<#{ fields.inspect }> not inject-able" unless
29
- fields.respond_to? :inject
30
-
31
- @fieldpos =
32
- fields.inject({}) do |h, f|
33
- unless String === f or Symbol === f
34
- raise ArgumentError, "<#{ f.inspect }> neither String nor Symbol"
35
- end
36
- h[f] = h.size
37
- h
38
- end
39
-
40
- @fields = fields
41
- end
42
- def pos f
43
- return @fieldpos[f] if @fieldpos.has_key? f
44
- f = f.to_s
45
- return @fieldpos[f] if @fieldpos.has_key? f
46
- f = f.intern
47
- return @fieldpos[f] if @fieldpos.has_key? f
48
- nil
49
- end
50
- end
51
- #
52
- # methods redefined to work with fields as well as numeric indexes
53
- #
54
- def [] idx, *args
55
- if @fieldset and (String === idx or Symbol === idx)
56
- pos = @fieldset.pos idx
57
- return nil unless pos
58
- super(pos, *args)
59
- else
60
- super
61
- end
62
- end
63
- def slice idx, *args
64
- if @fieldset and (String === idx or Symbol === idx)
65
- pos = @fieldset.pos idx
66
- return nil unless pos
67
- super(pos, *args)
68
- else
69
- super
70
- end
71
- end
72
-
73
- def []=(idx, *args)
74
- if @fieldset and (String === idx or Symbol === idx)
75
- pos = @fieldset.pos idx
76
- unless pos
77
- @fieldset.fields << idx
78
- @fieldset.fieldpos[idx] = pos = size
79
- end
80
- super(pos, *args)
81
- else
82
- super
83
- end
84
- end
85
- def at idx
86
- if @fieldset and (String === idx or Symbol === idx)
87
- pos = @fieldset.pos idx
88
- return nil unless pos
89
- super pos
90
- else
91
- super
92
- end
93
- end
94
- def delete_at idx
95
- if @fieldset and (String === idx or Symbol === idx)
96
- pos = @fieldset.pos idx
97
- return nil unless pos
98
- super pos
99
- else
100
- super
101
- end
102
- end
103
- def fill(obj, *args)
104
- idx = args.first
105
- if idx and @fieldset and (String === idx or Symbol === idx)
106
- idx = args.shift
107
- pos = @fieldset.pos idx
108
- super(obj, pos, *args)
109
- else
110
- super
111
- end
112
- end
113
-
114
- def values_at(*idxs)
115
- idxs.flatten!
116
- if @fieldset
117
- idxs.map!{|i| (String === i or Symbol === i) ? @fieldset.pos(i) : i}
118
- end
119
- super(*idxs)
120
- end
121
- def indices(*idxs)
122
- idxs.flatten!
123
- if @fieldset
124
- idxs.map!{|i| (String === i or Symbol === i) ? @fieldset.pos(i) : i}
125
- end
126
- super(*idxs)
127
- end
128
- def indexes(*idxs)
129
- idxs.flatten!
130
- if @fieldset
131
- idxs.map!{|i| (String === i or Symbol === i) ? @fieldset.pos(i) : i}
132
- end
133
- super(*idxs)
134
- end
135
-
136
- def slice!(*args)
137
- ret = self[*args]
138
- self[*args] = nil
139
- ret
140
- end
141
- def each_with_field
142
- each_with_index do |elem, i|
143
- yield elem, @fieldset.fields[i]
144
- end
145
- end
146
- #
147
- # methods which give a hash-like interface
148
- #
149
- def each_pair
150
- each_with_index do |elem, i|
151
- yield @fieldset.fields[i], elem
152
- end
153
- end
154
- def each_key
155
- @fieldset.each{|field| yield field}
156
- end
157
- def each_value *args, &block
158
- each *args, &block
159
- end
160
- def fetch key
161
- self[key] or raise IndexError, 'key not found'
162
- end
163
-
164
- def has_key? key
165
- @fieldset.fields.include? key
166
- end
167
- def member? key
168
- @fieldset.fields.include? key
169
- end
170
- def key? key
171
- @fieldset.fields.include? key
172
- end
173
-
174
- def has_value? value
175
- if respond_to? 'include?'
176
- self.include? value
177
- else
178
- a = []
179
- each{|val| a << val}
180
- a.include? value
181
- end
182
- end
183
- def value? value
184
- if respond_to? 'include?'
185
- self.include? value
186
- else
187
- a = []
188
- each{|val| a << val}
189
- a.include? value
190
- end
191
- end
192
-
193
- def keys
194
- fields
195
- end
196
- def store key, value
197
- self[key] = value
198
- end
199
- def values
200
- if respond_to? 'to_ary'
201
- self.to_ary
202
- else
203
- a = []
204
- each{|val| a << val}
205
- a
206
- end
207
- end
208
-
209
- def to_hash
210
- if respond_to? 'to_ary'
211
- h = {}
212
- @fieldset.fields.zip(to_ary){|f,e| h[f] = e}
213
- h
214
- else
215
- a = []
216
- each{|val| a << val}
217
- h = {}
218
- @fieldset.fields.zip(a){|f,e| h[f] = e}
219
- h
220
- end
221
- end
222
- def to_h
223
- if respond_to? 'to_ary'
224
- h = {}
225
- @fieldset.fields.zip(to_ary){|f,e| h[f] = e}
226
- h
227
- else
228
- a = []
229
- each{|val| a << val}
230
- h = {}
231
- @fieldset.fields.zip(a){|f,e| h[f] = e}
232
- h
233
- end
234
- end
235
-
236
- def update other
237
- other.each{|k,v| self[k] = v}
238
- to_hash
239
- end
240
- def replace other
241
- Hash === other ? update(other) : super
242
- end
243
- def invert
244
- to_hash.invert
245
- end
246
-
247
- def to_pairs
248
- fields.zip values
249
- end
250
- alias_method 'pairs', 'to_pairs'
251
-
252
- def copy
253
- cp = clone
254
- cp.fields = fields.clone
255
- cp
256
- end
257
-
258
- alias_method 'dup', 'copy'
259
- alias_method 'clone', 'copy'
260
-
261
- def deepcopy
262
- cp = Marshal.load(Marshal.dump(self))
263
- cp.fields = Marshal.load(Marshal.dump(self.fields))
264
- cp
265
- end
266
- end
267
- Arrayfields = ArrayFields
268
-
269
- module Arrayfields
270
- def self.new *pairs
271
- pairs = pairs.map{|pair| Enumerable === pair ? pair.to_a : pair}.flatten
272
- raise ArgumentError, "pairs must be evenly sized" unless(pairs.size % 2 == 0)
273
- (( array = [] )).fields = []
274
- 0.step(pairs.size - 2, 2) do |a|
275
- b = a + 1
276
- array[ pairs[a] ] = pairs[b]
277
- end
278
- array
279
- end
280
- def self.[] *pairs
281
- new *pairs
282
- end
283
- end
284
- def Arrayfields(*a, &b) Arrayfields.new(*a, &b) end
285
- #
286
- # Fieldable encapsulates methods in common for classes which may have their
287
- # fields set and subsequently be auto-extended by ArrayFields
288
- #
289
- module Fieldable
290
- #
291
- # sets fields an dynamically extends this Array instance with methods for
292
- # keyword access
293
- #
294
- def fields= fields
295
- extend ArrayFields unless ArrayFields === self
296
-
297
- @fieldset =
298
- if ArrayFields::FieldSet === fields
299
- fields
300
- else
301
- ArrayFields::FieldSet.new fields
302
- end
303
- end
304
- #
305
- # access to fieldset
306
- #
307
- attr_reader :fieldset
308
- #
309
- # access to field list
310
- #
311
- def fields
312
- @fieldset and @fieldset.fields
313
- end
314
- end
315
- #
316
- # Array instances are extened with two methods only: Fieldable#fields= and
317
- # Fieldable#fields. only when Fieldable#fields= is called will the full set
318
- # of ArrayFields methods auto-extend the Array instance. the Array class also
319
- # has added a class generator when the fields are known apriori.
320
- #
321
- class Array
322
- include Fieldable
323
-
324
- class << self
325
- def struct *fields
326
- fields = fields.flatten
327
- Class.new(self) do
328
- include ArrayFields
329
- const_set :FIELDS, ArrayFields::FieldSet.new(fields)
330
- fields.each do |field|
331
- field = field.to_s
332
- if field =~ %r/^[a-zA-Z_][a-zA-Z0-9_]*$/
333
- begin
334
- module_eval <<-code
335
- def #{ field } *a
336
- a.size == 0 ? self['#{ field }'] : (self.#{ field } = a.shift)
337
- end
338
- def #{ field }= value
339
- self['#{ field }'] = value
340
- end
341
- code
342
- rescue SyntaxError
343
- :by_ignoring_it
344
- end
345
- end
346
- end
347
- def initialize *a, &b
348
- super
349
- ensure
350
- @fieldset = self.class.const_get :FIELDS
351
- end
352
- def self.[] *elements
353
- array = new
354
- array.replace elements
355
- array
356
- end
357
- end
358
- end
359
- def fields *fields, &block
360
- (( array = new(&block) )).fields = fields.map{|x| Enumerable === x ? x.to_a : x}.flatten
361
- array
362
- end
363
- end
364
- end
365
- #
366
- # proxy class that allows an array to be wrapped in a way that still allows #
367
- # keyword access. also facilitate usage of ArrayFields with arraylike objects.
368
- # thnx to Sean O'Dell for the suggestion.
369
- #
370
- # sample usage
371
- #
372
- # fa = FieldedArray.new %w(zero one two), [0,1,2]
373
- # p fa['zero'] #=> 0
374
- #
375
- #
376
- class FieldedArray
377
- include Fieldable
378
- class << self
379
- def [](*pairs)
380
- pairs.flatten!
381
- raise ArgumentError, "argument must be key/val pairs" unless
382
- (pairs.size % 2 == 0)
383
- fields, elements = [], []
384
- while((f = pairs.shift) and (e = pairs.shift))
385
- fields << f and elements << e
386
- end
387
- new fields, elements
388
- end
389
- end
390
- def initialize fields = [], array = []
391
- @a = array
392
- self.fields = fields
393
- end
394
- def method_missing(meth, *args, &block)
395
- @a.send(meth, *args, &block)
396
- end
397
- delegates =
398
- %w(
399
- to_s
400
- to_str
401
- inspect
402
- )
403
- delegates.each do |meth|
404
- class_eval "def #{ meth }(*a,&b); @a.#{ meth }(*a,&b);end"
405
- end
406
- end
407
- Fieldedarray = FieldedArray
408
-
409
- class PseudoHash < ::Array
410
- class << self
411
- def [](*pairs)
412
- pairs.flatten!
413
- raise ArgumentError, "argument must be key/val pairs" unless
414
- (pairs.size % 2 == 0 and pairs.size >= 2)
415
- keys, values = [], []
416
- while((k = pairs.shift) and (v = pairs.shift))
417
- keys << k and values << v
418
- end
419
- new keys, values
420
- end
421
- end
422
- def initialize keys = [], values = []
423
- self.fields = keys
424
- self.replace values
425
- end
426
- def to_yaml opts = {}
427
- YAML::quick_emit object_id, opts do |out|
428
- out.map taguri, to_yaml_style do |map|
429
- each_pair{|f,v| map.add f,v}
430
- end
431
- end
432
- end
433
- end
434
- Pseudohash = PseudoHash
@@ -1,113 +0,0 @@
1
- module Attributes
2
- Attributes::VERSION = '4.0.0' unless defined? Attributes::VERSION
3
- def self.version() Attributes::VERSION end
4
-
5
- class List < ::Array
6
- def << element
7
- super
8
- self
9
- ensure
10
- uniq!
11
- index!
12
- end
13
- def index!
14
- @index ||= Hash.new
15
- each{|element| @index[element] = true}
16
- end
17
- def include? element
18
- @index ||= Hash.new
19
- @index[element] ? true : false
20
- end
21
- def initializers
22
- @initializers ||= Hash.new
23
- end
24
- end
25
-
26
- def attributes *a, &b
27
- unless a.empty?
28
- returned = Hash.new
29
-
30
- hashes, names = a.partition{|x| Hash === x}
31
- names_and_defaults = {}
32
- hashes.each{|h| names_and_defaults.update h}
33
- names.flatten.compact.each{|name| names_and_defaults.update name => nil}
34
-
35
- initializers = __attributes__.initializers
36
-
37
- names_and_defaults.each do |name, default|
38
- raise NameError, "bad instance variable name '@#{ name }'" if "@#{ name }" =~ %r/[!?=]$/o
39
- name = name.to_s
40
-
41
- initialize = b || lambda { default }
42
- initializer = lambda do |this|
43
- Object.instance_method('instance_eval').bind(this).call &initialize
44
- end
45
- initializer_id = initializer.object_id
46
- __attributes__.initializers[name] = initializer
47
-
48
- module_eval <<-code
49
- def #{ name }=(value)
50
- @#{ name } = value
51
- end
52
- code
53
- module_eval <<-code
54
- def #{ name }(*value)
55
- return self.#{ name } = value.first unless value.empty?
56
- #{ name }! unless defined? @#{ name }
57
- @#{ name }
58
- end
59
- code
60
- module_eval <<-code
61
- def #{ name }!
62
- initializer = ObjectSpace._id2ref #{ initializer_id }
63
- self.#{ name } = initializer.call(self)
64
- @#{ name }
65
- end
66
- code
67
- module_eval <<-code
68
- def #{ name }?
69
- #{ name }
70
- end
71
- code
72
-
73
- attributes << name
74
- returned[name] = initializer
75
- end
76
-
77
- returned
78
- else
79
- begin
80
- __attribute_list__
81
- rescue NameError
82
- singleton_class =
83
- class << self
84
- self
85
- end
86
- klass = self
87
- singleton_class.module_eval do
88
- attribute_list = List.new
89
- define_method('attribute_list'){ klass == self ? attribute_list : raise(NameError) }
90
- alias_method '__attribute_list__', 'attribute_list'
91
- end
92
- __attribute_list__
93
- end
94
- end
95
- end
96
-
97
- %w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
98
- end
99
-
100
- class Object
101
- def attributes *a, &b
102
- sc =
103
- class << self
104
- self
105
- end
106
- sc.attributes *a, &b
107
- end
108
- %w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
109
- end
110
-
111
- class Module
112
- include Attributes
113
- end
@@ -1,52 +0,0 @@
1
- module Pervasives
2
- VERSION = "1.1.0"
3
- def self.version() VERSION end
4
-
5
- Methods = Hash.new{|h,k| h[k] = {}}
6
-
7
- [Class, Module, Object].each do |type|
8
- type.instance_methods.each do |m|
9
- Methods[type]["#{ m }"] = type.instance_method m
10
- end
11
- end
12
-
13
- def self.call o, m, *a, &b
14
- list =
15
- case o
16
- when Class then [Class, Module, Object]
17
- when Module then [Module, Object]
18
- when Object then [Object]
19
- end
20
- type = list.detect{|type| Methods[type]["#{ m }"]}
21
- m = Methods[type]["#{ m }"]
22
- ( m ).bind( o ).call( *a, &b )
23
- end
24
-
25
- class ::Object
26
- def __pervasive__ m, *a, &b
27
- Pervasives.call self, m, *a, &b
28
- end
29
- end
30
-
31
- class Proxy
32
- instance_methods.each{|m| undef_method m unless m[%r/__/]}
33
-
34
- def initialize obj
35
- @obj = obj
36
- end
37
-
38
- def method_missing m, *a, &b
39
- Pervasives.call @obj, m, *a, &b
40
- end
41
- end
42
-
43
- def self.new *a, &b
44
- Proxy.new *a, &b
45
- end
46
-
47
- class ::Object
48
- def Pervasives *a, &b
49
- Proxy.new *a, &b
50
- end
51
- end
52
- end