queue_classic 1.0.1 → 1.0.2

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 (3) hide show
  1. data/lib/queue_classic/okjson.rb +40 -15
  2. data/readme.md +2 -1
  3. metadata +3 -3
@@ -1,5 +1,7 @@
1
1
  module QC
2
- # Copyright 2011 Keith Rarick
2
+ # encoding: UTF-8
3
+ #
4
+ # Copyright 2011, 2012 Keith Rarick
3
5
  #
4
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
7
  # of this software and associated documentation files (the "Software"), to deal
@@ -261,6 +263,12 @@ module OkJson
261
263
  def unquote(q)
262
264
  q = q[1...-1]
263
265
  a = q.dup # allocate a big enough string
266
+ rubydoesenc = false
267
+ # In ruby >= 1.9, a[w] is a codepoint, not a byte.
268
+ if a.class.method_defined?(:force_encoding)
269
+ a.force_encoding('UTF-8')
270
+ rubydoesenc = true
271
+ end
264
272
  r, w = 0, 0
265
273
  while r < q.length
266
274
  c = q[r]
@@ -298,7 +306,12 @@ module OkJson
298
306
  end
299
307
  end
300
308
  end
301
- w += ucharenc(a, w, uchar)
309
+ if rubydoesenc
310
+ a[w] = '' << uchar
311
+ w += 1
312
+ else
313
+ w += ucharenc(a, w, uchar)
314
+ end
302
315
  else
303
316
  raise Error, "invalid escape char #{q[r]} in \"#{q}\""
304
317
  end
@@ -308,6 +321,8 @@ module OkJson
308
321
  # Copy anything else byte-for-byte.
309
322
  # Valid UTF-8 will remain valid UTF-8.
310
323
  # Invalid UTF-8 will remain invalid UTF-8.
324
+ # In ruby >= 1.9, c is a codepoint, not a byte,
325
+ # in which case this is still what we want.
311
326
  a[w] = c
312
327
  r += 1
313
328
  w += 1
@@ -442,6 +457,10 @@ module OkJson
442
457
  t = StringIO.new
443
458
  t.putc(?")
444
459
  r = 0
460
+
461
+ # In ruby >= 1.9, s[r] is a codepoint, not a byte.
462
+ rubydoesenc = s.class.method_defined?(:encoding)
463
+
445
464
  while r < s.length
446
465
  case s[r]
447
466
  when ?" then t.print('\\"')
@@ -456,21 +475,13 @@ module OkJson
456
475
  case true
457
476
  when Spc <= c && c <= ?~
458
477
  t.putc(c)
459
- when true
478
+ when rubydoesenc
479
+ u = c.ord
480
+ surrenc(t, u)
481
+ else
460
482
  u, size = uchardec(s, r)
461
483
  r += size - 1 # we add one more at the bottom of the loop
462
- if u < 0x10000
463
- t.print('\\u')
464
- hexenc4(t, u)
465
- else
466
- u1, u2 = unsubst(u)
467
- t.print('\\u')
468
- hexenc4(t, u1)
469
- t.print('\\u')
470
- hexenc4(t, u2)
471
- end
472
- else
473
- # invalid byte; skip it
484
+ surrenc(t, u)
474
485
  end
475
486
  end
476
487
  r += 1
@@ -480,6 +491,20 @@ module OkJson
480
491
  end
481
492
 
482
493
 
494
+ def surrenc(t, u)
495
+ if u < 0x10000
496
+ t.print('\\u')
497
+ hexenc4(t, u)
498
+ else
499
+ u1, u2 = unsubst(u)
500
+ t.print('\\u')
501
+ hexenc4(t, u1)
502
+ t.print('\\u')
503
+ hexenc4(t, u2)
504
+ end
505
+ end
506
+
507
+
483
508
  def hexenc4(t, u)
484
509
  t.putc(Hex[(u>>12)&0xf])
485
510
  t.putc(Hex[(u>>8)&0xf])
data/readme.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # queue_classic
2
- v1.0.0
2
+
3
+ v1.0.2
3
4
 
4
5
  queue_classic is a PostgreSQL-backed queueing library that is focused on
5
6
  concurrent job locking, minimizing database load & providing a simple &
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queue_classic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
16
- requirement: &16027180 !ruby/object:Gem::Requirement
16
+ requirement: &15604460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.11.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16027180
24
+ version_requirements: *15604460
25
25
  description: queue_classic is a queueing library for Ruby apps. (Rails, Sinatra, Etc...)
26
26
  queue_classic features asynchronous job polling, database maintained locks and no
27
27
  ridiculous dependencies. As a matter of fact, queue_classic only requires pg.