rhodes 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Manifest.txt +0 -61
  2. data/Rakefile +11 -13
  3. data/lib/rhodes.rb +2 -2
  4. metadata +33 -77
  5. data/History.txt +0 -40
  6. data/README.rdoc +0 -2
  7. data/bin/rhogen +0 -8
  8. data/generators/rhogen.rb +0 -131
  9. data/generators/templates/application/application.rb +0 -4
  10. data/generators/templates/application/index.erb +0 -11
  11. data/generators/templates/application/layout.erb +0 -17
  12. data/generators/templates/model/config.rb +0 -3
  13. data/generators/templates/model/controller.rb +0 -49
  14. data/generators/templates/model/edit.erb +0 -21
  15. data/generators/templates/model/index.erb +0 -10
  16. data/generators/templates/model/new.erb +0 -16
  17. data/generators/templates/model/show.erb +0 -6
  18. data/generators/templates/source/source_adapter.rb +0 -56
  19. data/lib/ServeME.rb +0 -7
  20. data/lib/TestServe.rb +0 -9
  21. data/lib/bsearch.rb +0 -120
  22. data/lib/builtinME.rb +0 -588
  23. data/lib/date.rb +0 -1792
  24. data/lib/date/format.rb +0 -1339
  25. data/lib/dateME.rb +0 -24
  26. data/lib/erb.rb +0 -896
  27. data/lib/find.rb +0 -81
  28. data/lib/rational.rb +0 -19
  29. data/lib/rationalME.rb +0 -530
  30. data/lib/rho.rb +0 -1
  31. data/lib/rho/render.rb +0 -51
  32. data/lib/rho/rho.rb +0 -240
  33. data/lib/rho/rhoapplication.rb +0 -36
  34. data/lib/rho/rhocontact.rb +0 -110
  35. data/lib/rho/rhocontroller.rb +0 -35
  36. data/lib/rho/rhofsconnector.rb +0 -32
  37. data/lib/rho/rhosupport.rb +0 -139
  38. data/lib/rho/rhoviewhelpers.rb +0 -121
  39. data/lib/rhoframework.rb +0 -38
  40. data/lib/rhofsconnector.rb +0 -1
  41. data/lib/rhom.rb +0 -1
  42. data/lib/rhom/rhom.rb +0 -58
  43. data/lib/rhom/rhom_db_adapter.rb +0 -185
  44. data/lib/rhom/rhom_db_adapterME.rb +0 -93
  45. data/lib/rhom/rhom_object.rb +0 -65
  46. data/lib/rhom/rhom_object_factory.rb +0 -197
  47. data/lib/rhom/rhom_source.rb +0 -60
  48. data/lib/singleton.rb +0 -137
  49. data/lib/time.rb +0 -489
  50. data/spec/app_generator_spec.rb +0 -33
  51. data/spec/app_manifest.txt +0 -3
  52. data/spec/configs/account.rb +0 -3
  53. data/spec/configs/case.rb +0 -3
  54. data/spec/configs/employee.rb +0 -3
  55. data/spec/generator_spec_helper.rb +0 -12
  56. data/spec/model_generator_spec.rb +0 -36
  57. data/spec/rho_controller_spec.rb +0 -139
  58. data/spec/rho_spec.rb +0 -61
  59. data/spec/rhom_object_factory_spec.rb +0 -132
  60. data/spec/rhom_spec.rb +0 -45
  61. data/spec/source_generator_spec.rb +0 -27
  62. data/spec/spec_helper.rb +0 -48
  63. data/spec/stubs.rb +0 -31
  64. data/spec/syncdbtest.sqlite +0 -0
  65. data/tasks/rspec.rake +0 -34
@@ -1,489 +0,0 @@
1
-
2
- #
3
- # == Introduction
4
- #
5
- # This library extends the Time class:
6
- # * conversion between date string and time object.
7
- # * date-time defined by RFC 2822
8
- # * HTTP-date defined by RFC 2616
9
- # * dateTime defined by XML Schema Part 2: Datatypes (ISO 8601)
10
- # * various formats handled by Date._parse (string to time only)
11
- #
12
- # == Design Issues
13
- #
14
- # === Specialized interface
15
- #
16
- # This library provides methods dedicated to special purposes:
17
- # * RFC 2822, RFC 2616 and XML Schema.
18
- # * They makes usual life easier.
19
- #
20
- # === Doesn't depend on strftime
21
- #
22
- # This library doesn't use +strftime+. Especially #rfc2822 doesn't depend
23
- # on +strftime+ because:
24
- #
25
- # * %a and %b are locale sensitive
26
- #
27
- # Since they are locale sensitive, they may be replaced to
28
- # invalid weekday/month name in some locales.
29
- # Since ruby-1.6 doesn't invoke setlocale by default,
30
- # the problem doesn't arise until some external library invokes setlocale.
31
- # Ruby/GTK is the example of such library.
32
- #
33
- # * %z is not portable
34
- #
35
- # %z is required to generate zone in date-time of RFC 2822
36
- # but it is not portable.
37
- #
38
- # == Revision Information
39
- #
40
- # $Id$
41
- #
42
-
43
- require 'date/format'
44
- if defined? RHO_ME
45
- require 'dateME'
46
- end
47
-
48
- #
49
- # Implements the extensions to the Time class that are described in the
50
- # documentation for the time.rb library.
51
- #
52
- class Time
53
- class << Time
54
-
55
- ZoneOffset = {
56
- 'UTC' => 0,
57
- # ISO 8601
58
- 'Z' => 0,
59
- # RFC 822
60
- 'UT' => 0, 'GMT' => 0,
61
- 'EST' => -5, 'EDT' => -4,
62
- 'CST' => -6, 'CDT' => -5,
63
- 'MST' => -7, 'MDT' => -6,
64
- 'PST' => -8, 'PDT' => -7,
65
- # Following definition of military zones is original one.
66
- # See RFC 1123 and RFC 2822 for the error in RFC 822.
67
- 'A' => +1, 'B' => +2, 'C' => +3, 'D' => +4, 'E' => +5, 'F' => +6,
68
- 'G' => +7, 'H' => +8, 'I' => +9, 'K' => +10, 'L' => +11, 'M' => +12,
69
- 'N' => -1, 'O' => -2, 'P' => -3, 'Q' => -4, 'R' => -5, 'S' => -6,
70
- 'T' => -7, 'U' => -8, 'V' => -9, 'W' => -10, 'X' => -11, 'Y' => -12,
71
- }
72
- def zone_offset(zone, year=self.now.year)
73
- off = nil
74
- zone = zone.upcase
75
- if /\A([+-])(\d\d):?(\d\d)\z/ =~ zone
76
- off = ($1 == '-' ? -1 : 1) * ($2.to_i * 60 + $3.to_i) * 60
77
- elsif /\A[+-]\d\d\z/ =~ zone
78
- off = zone.to_i * 3600
79
- elsif ZoneOffset.include?(zone)
80
- off = ZoneOffset[zone] * 3600
81
- elsif ((t = self.local(year, 1, 1)).zone.upcase == zone rescue false)
82
- off = t.utc_offset
83
- elsif ((t = self.local(year, 7, 1)).zone.upcase == zone rescue false)
84
- off = t.utc_offset
85
- end
86
- off
87
- end
88
-
89
- def zone_utc?(zone)
90
- # * +0000 means localtime. [RFC 2822]
91
- # * GMT is a localtime abbreviation in Europe/London, etc.
92
- if /\A(?:-00:00|-0000|-00|UTC|Z|UT)\z/i =~ zone
93
- true
94
- else
95
- false
96
- end
97
- end
98
- private :zone_utc?
99
-
100
- LeapYearMonthDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
101
- CommonYearMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
102
- def month_days(y, m)
103
- if ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)
104
- LeapYearMonthDays[m-1]
105
- else
106
- CommonYearMonthDays[m-1]
107
- end
108
- end
109
- private :month_days
110
-
111
- def apply_offset(year, mon, day, hour, min, sec, off)
112
- if off < 0
113
- off = -off
114
- off, o = off.divmod(60)
115
- if o != 0 then sec += o; o, sec = sec.divmod(60); off += o end
116
- off, o = off.divmod(60)
117
- if o != 0 then min += o; o, min = min.divmod(60); off += o end
118
- off, o = off.divmod(24)
119
- if o != 0 then hour += o; o, hour = hour.divmod(24); off += o end
120
- if off != 0
121
- day += off
122
- if month_days(year, mon) < day
123
- mon += 1
124
- if 12 < mon
125
- mon = 1
126
- year += 1
127
- end
128
- day = 1
129
- end
130
- end
131
- elsif 0 < off
132
- off, o = off.divmod(60)
133
- if o != 0 then sec -= o; o, sec = sec.divmod(60); off -= o end
134
- off, o = off.divmod(60)
135
- if o != 0 then min -= o; o, min = min.divmod(60); off -= o end
136
- off, o = off.divmod(24)
137
- if o != 0 then hour -= o; o, hour = hour.divmod(24); off -= o end
138
- if off != 0 then
139
- day -= off
140
- if day < 1
141
- mon -= 1
142
- if mon < 1
143
- year -= 1
144
- mon = 12
145
- end
146
- day = month_days(year, mon)
147
- end
148
- end
149
- end
150
- return year, mon, day, hour, min, sec
151
- end
152
- private :apply_offset
153
-
154
- def make_time(year, mon, day, hour, min, sec, sec_fraction, zone, now)
155
- usec = nil
156
- usec = sec_fraction * 1000000 if sec_fraction
157
- if now
158
- begin
159
- break if year; year = now.year
160
- break if mon; mon = now.mon
161
- break if day; day = now.day
162
- break if hour; hour = now.hour
163
- break if min; min = now.min
164
- break if sec; sec = now.sec
165
- break if sec_fraction; usec = now.tv_usec
166
- end until true
167
- end
168
-
169
- year ||= 1970
170
- mon ||= 1
171
- day ||= 1
172
- hour ||= 0
173
- min ||= 0
174
- sec ||= 0
175
- usec ||= 0
176
-
177
- off = nil
178
- off = zone_offset(zone, year) if zone
179
-
180
- if off
181
- year, mon, day, hour, min, sec =
182
- apply_offset(year, mon, day, hour, min, sec, off)
183
- t = self.utc(year, mon, day, hour, min, sec, usec)
184
- t.localtime if !zone_utc?(zone)
185
- t
186
- else
187
- self.local(year, mon, day, hour, min, sec, usec)
188
- end
189
- end
190
- private :make_time
191
-
192
- #
193
- # Parses +date+ using Date._parse and converts it to a Time object.
194
- #
195
- # If a block is given, the year described in +date+ is converted by the
196
- # block. For example:
197
- #
198
- # Time.parse(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
199
- #
200
- # If the upper components of the given time are broken or missing, they are
201
- # supplied with those of +now+. For the lower components, the minimum
202
- # values (1 or 0) are assumed if broken or missing. For example:
203
- #
204
- # # Suppose it is "Thu Nov 29 14:33:20 GMT 2001" now and
205
- # # your timezone is GMT:
206
- # Time.parse("16:30") #=> Thu Nov 29 16:30:00 GMT 2001
207
- # Time.parse("7/23") #=> Mon Jul 23 00:00:00 GMT 2001
208
- # Time.parse("Aug 31") #=> Fri Aug 31 00:00:00 GMT 2001
209
- #
210
- # Since there are numerous conflicts among locally defined timezone
211
- # abbreviations all over the world, this method is not made to
212
- # understand all of them. For example, the abbreviation "CST" is
213
- # used variously as:
214
- #
215
- # -06:00 in America/Chicago,
216
- # -05:00 in America/Havana,
217
- # +08:00 in Asia/Harbin,
218
- # +09:30 in Australia/Darwin,
219
- # +10:30 in Australia/Adelaide,
220
- # etc.
221
- #
222
- # Based on the fact, this method only understands the timezone
223
- # abbreviations described in RFC 822 and the system timezone, in the
224
- # order named. (i.e. a definition in RFC 822 overrides the system
225
- # timezone definition.) The system timezone is taken from
226
- # <tt>Time.local(year, 1, 1).zone</tt> and
227
- # <tt>Time.local(year, 7, 1).zone</tt>.
228
- # If the extracted timezone abbreviation does not match any of them,
229
- # it is ignored and the given time is regarded as a local time.
230
- #
231
- # ArgumentError is raised if Date._parse cannot extract information from
232
- # +date+ or Time class cannot represent specified date.
233
- #
234
- # This method can be used as fail-safe for other parsing methods as:
235
- #
236
- # Time.rfc2822(date) rescue Time.parse(date)
237
- # Time.httpdate(date) rescue Time.parse(date)
238
- # Time.xmlschema(date) rescue Time.parse(date)
239
- #
240
- # A failure for Time.parse should be checked, though.
241
- #
242
- def parse(date, now=self.now)
243
- d = Date._parse(date, false)
244
- year = d[:year]
245
- year = yield(year) if year && block_given?
246
- make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
247
- end
248
-
249
- #
250
- # Parses +date+ using Date._strptime and converts it to a Time object.
251
- #
252
- # If a block is given, the year described in +date+ is converted by the
253
- # block. For example:
254
- #
255
- # Time.strptime(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
256
- def strptime(date, format, now=self.now)
257
- d = Date._strptime(date, format)
258
- raise ArgumentError, "invalid strptime format - `#{format}'" unless d
259
- year = d[:year]
260
- year = yield(year) if year && block_given?
261
- make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
262
- end
263
-
264
- MonthValue = {
265
- 'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6,
266
- 'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' =>10, 'NOV' =>11, 'DEC' =>12
267
- }
268
-
269
- #
270
- # Parses +date+ as date-time defined by RFC 2822 and converts it to a Time
271
- # object. The format is identical to the date format defined by RFC 822 and
272
- # updated by RFC 1123.
273
- #
274
- # ArgumentError is raised if +date+ is not compliant with RFC 2822
275
- # or Time class cannot represent specified date.
276
- #
277
- # See #rfc2822 for more information on this format.
278
- #
279
- def rfc2822(date)
280
- if /\A\s*
281
- (?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s*,\s*)?
282
- (\d{1,2})\s+
283
- (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+
284
- (\d{2,})\s+
285
- (\d{2})\s*
286
- :\s*(\d{2})\s*
287
- (?::\s*(\d{2}))?\s+
288
- ([+-]\d{4}|
289
- UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Z])/ix =~ date
290
- # Since RFC 2822 permit comments, the regexp has no right anchor.
291
- day = $1.to_i
292
- mon = MonthValue[$2.upcase]
293
- year = $3.to_i
294
- hour = $4.to_i
295
- min = $5.to_i
296
- sec = $6 ? $6.to_i : 0
297
- zone = $7
298
-
299
- # following year completion is compliant with RFC 2822.
300
- year = if year < 50
301
- 2000 + year
302
- elsif year < 1000
303
- 1900 + year
304
- else
305
- year
306
- end
307
-
308
- year, mon, day, hour, min, sec =
309
- apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
310
- t = self.utc(year, mon, day, hour, min, sec)
311
- t.localtime if !zone_utc?(zone)
312
- t
313
- else
314
- raise ArgumentError.new("not RFC 2822 compliant date: #{date.inspect}")
315
- end
316
- end
317
- alias rfc822 rfc2822
318
-
319
- #
320
- # Parses +date+ as HTTP-date defined by RFC 2616 and converts it to a Time
321
- # object.
322
- #
323
- # ArgumentError is raised if +date+ is not compliant with RFC 2616 or Time
324
- # class cannot represent specified date.
325
- #
326
- # See #httpdate for more information on this format.
327
- #
328
- def httpdate(date)
329
- if /\A\s*
330
- (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\x20
331
- (\d{2})\x20
332
- (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
333
- (\d{4})\x20
334
- (\d{2}):(\d{2}):(\d{2})\x20
335
- GMT
336
- \s*\z/ix =~ date
337
- self.rfc2822(date)
338
- elsif /\A\s*
339
- (?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),\x20
340
- (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d)\x20
341
- (\d\d):(\d\d):(\d\d)\x20
342
- GMT
343
- \s*\z/ix =~ date
344
- year = $3.to_i
345
- if year < 50
346
- year += 2000
347
- else
348
- year += 1900
349
- end
350
- self.utc(year(), $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i)
351
- elsif /\A\s*
352
- (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\x20
353
- (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
354
- (\d\d|\x20\d)\x20
355
- (\d\d):(\d\d):(\d\d)\x20
356
- (\d{4})
357
- \s*\z/ix =~ date
358
- self.utc($6.to_i, MonthValue[$1.upcase], $2.to_i,
359
- $3.to_i, $4.to_i, $5.to_i)
360
- else
361
- raise ArgumentError.new("not RFC 2616 compliant date: #{date.inspect}")
362
- end
363
- end
364
-
365
- #
366
- # Parses +date+ as dateTime defined by XML Schema and converts it to a Time
367
- # object. The format is restricted version of the format defined by ISO
368
- # 8601.
369
- #
370
- # ArgumentError is raised if +date+ is not compliant with the format or Time
371
- # class cannot represent specified date.
372
- #
373
- # See #xmlschema for more information on this format.
374
- #
375
- def xmlschema(date)
376
- if /\A\s*
377
- (-?\d+)-(\d\d)-(\d\d)
378
- T
379
- (\d\d):(\d\d):(\d\d)
380
- (\.\d+)?
381
- (Z|[+-]\d\d:\d\d)?
382
- \s*\z/ix =~ date
383
- year = $1.to_i
384
- mon = $2.to_i
385
- day = $3.to_i
386
- hour = $4.to_i
387
- min = $5.to_i
388
- sec = $6.to_i
389
- usec = 0
390
- if $7
391
- usec = Rational($7) * 1000000
392
- end
393
- if $8
394
- zone = $8
395
- year, mon, day, hour, min, sec =
396
- apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
397
- self.utc(year, mon, day, hour, min, sec, usec)
398
- else
399
- self.local(year, mon, day, hour, min, sec, usec)
400
- end
401
- else
402
- raise ArgumentError.new("invalid date: #{date.inspect}")
403
- end
404
- end
405
- alias iso8601 xmlschema
406
- end # class << self
407
-
408
- #
409
- # Returns a string which represents the time as date-time defined by RFC 2822:
410
- #
411
- # day-of-week, DD month-name CCYY hh:mm:ss zone
412
- #
413
- # where zone is [+-]hhmm.
414
- #
415
- # If +self+ is a UTC time, -0000 is used as zone.
416
- #
417
- def rfc2822
418
- sprintf('%s, %02d %s %d %02d:%02d:%02d ',
419
- RFC2822_DAY_NAME[wday()],
420
- day(), RFC2822_MONTH_NAME[mon()-1], year(),
421
- hour(), min(), sec() ) +
422
- if utc?
423
- '-0000'
424
- else
425
- off = utc_offset
426
- sign = off < 0 ? '-' : '+'
427
- sprintf('%s%02d%02d', sign, *(off.abs / 60).divmod(60))
428
- end
429
- end
430
- alias rfc822 rfc2822
431
-
432
- RFC2822_DAY_NAME = [
433
- 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
434
- ]
435
- RFC2822_MONTH_NAME = [
436
- 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
437
- 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
438
- ]
439
-
440
- #
441
- # Returns a string which represents the time as rfc1123-date of HTTP-date
442
- # defined by RFC 2616:
443
- #
444
- # day-of-week, DD month-name CCYY hh:mm:ss GMT
445
- #
446
- # Note that the result is always UTC (GMT).
447
- #
448
- def httpdate
449
- t = dup.utc
450
- sprintf('%s, %02d %s %d %02d:%02d:%02d GMT',
451
- RFC2822_DAY_NAME[t.wday],
452
- t.day, RFC2822_MONTH_NAME[t.mon-1], t.year,
453
- t.hour, t.min, t.sec)
454
- end
455
-
456
- #
457
- # Returns a string which represents the time as dateTime defined by XML
458
- # Schema:
459
- #
460
- # CCYY-MM-DDThh:mm:ssTZD
461
- # CCYY-MM-DDThh:mm:ss.sssTZD
462
- #
463
- # where TZD is Z or [+-]hh:mm.
464
- #
465
- # If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
466
- #
467
- # +fractional_seconds+ specifies a number of digits of fractional seconds.
468
- # Its default value is 0.
469
- #
470
- def xmlschema(fraction_digits=0)
471
- sprintf('%d-%02d-%02dT%02d:%02d:%02d',
472
- year, mon, day, hour, min, sec) +
473
- if fraction_digits == 0
474
- ''
475
- elsif fraction_digits <= 9
476
- '.' + sprintf('%09d', nsec)[0, fraction_digits]
477
- else
478
- '.' + sprintf('%09d', nsec) + '0' * (fraction_digits - 9)
479
- end +
480
- if utc?
481
- 'Z'
482
- else
483
- off = utc_offset
484
- sign = off < 0 ? '-' : '+'
485
- sprintf('%s%02d:%02d', sign, *(off.abs / 60).divmod(60))
486
- end
487
- end
488
- alias iso8601 xmlschema
489
- end