rufus-jig 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,6 +1,14 @@
1
1
 
2
2
  = rufus-jig CHANGELOG.txt
3
3
 
4
+
5
+ == rufus-jig - 0.1.10 released 2010/01/06
6
+
7
+ - test/con to test/conc (win issue), thanks gauched
8
+ - made net/http Http thread-safe (serialization through synchronization)
9
+ - :re_put_ok => false rework (deleting at first)
10
+
11
+
4
12
  == rufus-jig - 0.1.9 released 2009/12/29
5
13
 
6
14
  - Couch now handling conflict re-get by itself
data/CREDITS.txt CHANGED
@@ -8,3 +8,7 @@ Kenneth Kalmer - http://github.com/kennethkalmer
8
8
 
9
9
  Torsten Schoenebaum - http://github.com/tosch
10
10
 
11
+ == feedback
12
+
13
+ gauched - http://github.com/gauched
14
+
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2009-2009, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ Jeweler::Tasks.new do |gem|
26
26
  gem.summary = 'An HTTP client, greedy with JSON content, GETting conditionally.'
27
27
 
28
28
  gem.description = %{
29
- Json Internet Get.
29
+ Json Interwebs Get.
30
30
 
31
31
  An HTTP client, greedy with JSON content, GETting conditionally.
32
32
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -50,9 +50,8 @@ module Rufus::Jig
50
50
  end
51
51
 
52
52
  if @opts[:re_put_ok] == false && payload['_rev']
53
- cur = get(path)
54
- return true if cur.nil?
55
- return cur if cur['_rev'] != payload['_rev']
53
+ rr = delete(path, payload['_rev'])
54
+ return rr unless rr.nil?
56
55
  end
57
56
 
58
57
  path = adjust(path)
@@ -103,7 +102,16 @@ module Rufus::Jig
103
102
  @http.delete(path)
104
103
  end
105
104
 
106
- r == true ? true : nil
105
+ if r == true # conflict
106
+
107
+ doc = @http.get(adjust(doc_or_path['_id']))
108
+ doc ? doc : true
109
+ # returns the doc if present or true if the doc is gone
110
+
111
+ else # delete is successful
112
+
113
+ nil
114
+ end
107
115
  end
108
116
 
109
117
  protected
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -167,7 +167,7 @@ module Rufus::Jig
167
167
 
168
168
  return Rufus::Jig.marshal_copy(cached.last) if r.status == 304
169
169
  return nil if method == :get && r.status == 404
170
- return true if r.status == 409
170
+ return true if [ 404, 409 ].include?(r.status)
171
171
 
172
172
  raise @error_class.new(r.status, r.body) \
173
173
  if r.status >= 400 && r.status < 600
@@ -457,6 +457,7 @@ elsif defined?( EventMachine::HttpRequest )
457
457
 
458
458
  else
459
459
 
460
+ require 'thread'
460
461
  require 'net/http'
461
462
 
462
463
  class Rufus::Jig::HttpResponse
@@ -491,6 +492,8 @@ else
491
492
  @options[:user_agent] =
492
493
  opts[:user_agent] ||
493
494
  "#{self.class} #{Rufus::Jig::VERSION} (net/http)"
495
+
496
+ @mutex = Mutex.new
494
497
  end
495
498
 
496
499
  protected
@@ -517,16 +520,19 @@ else
517
520
 
518
521
  def do_request (method, path, data, opts)
519
522
 
520
- path = '/' if path == ''
523
+ @mutex.synchronize do
524
+
525
+ path = '/' if path == ''
521
526
 
522
- req = eval("Net::HTTP::#{method.to_s.capitalize}").new(path)
527
+ req = eval("Net::HTTP::#{method.to_s.capitalize}").new(path)
523
528
 
524
- req['User-Agent'] = options[:user_agent]
525
- opts.each { |k, v| req[k] = v if k.is_a?(String) }
529
+ req['User-Agent'] = options[:user_agent]
530
+ opts.each { |k, v| req[k] = v if k.is_a?(String) }
526
531
 
527
- req.body = data ? data : ''
532
+ req.body = data ? data : ''
528
533
 
529
- Rufus::Jig::HttpResponse.new(@http.start { @http.request(req) })
534
+ Rufus::Jig::HttpResponse.new(@http.start { |h| h.request(req) })
535
+ end
530
536
  end
531
537
  end
532
538
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Rufus
3
3
  module Jig
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
6
6
  end
7
7
 
data/lib/rufus/jig.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
data/rufus-jig.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rufus-jig}
8
- s.version = "0.1.9"
8
+ s.version = "0.1.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux", "Kenneth Kalmer"]
12
- s.date = %q{2009-12-29}
12
+ s.date = %q{2010-01-06}
13
13
  s.description = %q{
14
- Json Internet Get.
14
+ Json Interwebs Get.
15
15
 
16
16
  An HTTP client, greedy with JSON content, GETting conditionally.
17
17
 
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/rufus/jig/version.rb",
39
39
  "rufus-jig.gemspec",
40
40
  "test/base.rb",
41
+ "test/conc/put_vs_delete.rb",
41
42
  "test/couch_base.rb",
42
43
  "test/ct_0_couch.rb",
43
44
  "test/ct_1_couchdb.rb",
@@ -0,0 +1,28 @@
1
+
2
+ $:.unshift('lib')
3
+
4
+ require 'patron'
5
+ require 'yajl'
6
+ require 'rufus/jig'
7
+
8
+ C0 = Rufus::Jig::Couch.new('127.0.0.1', 5984, 'test0', :re_put_ok => false)
9
+ C1 = Rufus::Jig::Couch.new('127.0.0.1', 5984, 'test0', :re_put_ok => false)
10
+
11
+ d = C0.get('nada')
12
+ C0.delete(d) if d
13
+
14
+ C0.put({ '_id' => 'nada', 'where' => 'London' })
15
+ d = C0.get('nada')
16
+
17
+ t1 = Thread.new do
18
+ p [ Thread.current.object_id, :delete, d['_rev'], C1.delete(d) ]
19
+ end
20
+ t0 = Thread.new do
21
+ p [ Thread.current.object_id, :put, d['_rev'], C0.put(d) ]
22
+ end
23
+
24
+ sleep 0.500
25
+
26
+ p C0.get('nada')
27
+ p C1.get('nada')
28
+
data/test/ct_1_couchdb.rb CHANGED
@@ -143,7 +143,7 @@ class CtCouchDbTest < Test::Unit::TestCase
143
143
 
144
144
  r = @c.delete(doc)
145
145
 
146
- assert_equal true, r
146
+ assert_equal rev, r['_rev']
147
147
  end
148
148
 
149
149
  def test_get_doc_304
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-jig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-29 00:00:00 +09:00
13
+ date: 2010-01-06 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,7 @@ dependencies:
43
43
  - !ruby/object:Gem::Version
44
44
  version: "0"
45
45
  version:
46
- description: "\n Json Internet Get.\n\n An HTTP client, greedy with JSON content, GETting conditionally.\n\n Uses Patron and Yajl-ruby whenever possible.\n "
46
+ description: "\n Json Interwebs Get.\n\n An HTTP client, greedy with JSON content, GETting conditionally.\n\n Uses Patron and Yajl-ruby whenever possible.\n "
47
47
  email: jmettraux@gmail.com
48
48
  executables: []
49
49
 
@@ -68,6 +68,7 @@ files:
68
68
  - lib/rufus/jig/version.rb
69
69
  - rufus-jig.gemspec
70
70
  - test/base.rb
71
+ - test/conc/put_vs_delete.rb
71
72
  - test/couch_base.rb
72
73
  - test/ct_0_couch.rb
73
74
  - test/ct_1_couchdb.rb