couchbase-id 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a42cd935e03306c97229c948846477f7644036d9
4
- data.tar.gz: f5c44e666e4d4f1d7e02315d88abec759aefc16b
3
+ metadata.gz: 046810f6c16e5260ee2144091c69097392ca0ee2
4
+ data.tar.gz: 63d197aa49e4422fba7e8c901fbf8333d3c2a793
5
5
  SHA512:
6
- metadata.gz: d241fe6f412f431c4ca8c65b9b3b7dfe90f1ff111f400cc01ca3e2896cf4545e51e977b74e952687a2886bced0ec383c475f743f7c4bb193a18150546c54aa1b
7
- data.tar.gz: 51693ff03b89787c110d4628b709222ddf77b74e1688af71dde7f7986f7bcbae8c559500db9fff5ede74c9817b43066192cb7874e7681f3be4a35ea96ec95e12
6
+ metadata.gz: 4e043907810bedd9d349bac8483dcda50ee6f3192a3753e55efb0e9ed4c2fcdbceb655cbcfdae0aeff5975c5f981e7f4c9a393036787e11922fa3a289d7c3d38
7
+ data.tar.gz: 0f64d37efafa4aa8bfa99721e0b677439d0676ea46a608bfa76a4fd1e12deeacf689d3c5b22048bbc8dd95eee5d9530279234a4cb9f566c0ab0a91c4fa2d86aa
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/couchbase-id.gemspec CHANGED
@@ -13,11 +13,6 @@ Gem::Specification.new do |gem|
13
13
  gem.required_ruby_version = '>= 1.9.2'
14
14
  gem.require_paths = ['lib']
15
15
 
16
- if RUBY_PLATFORM == 'java'
17
- gem.add_runtime_dependency 'couchbase-jruby-model' # couchbase active model orm
18
- else
19
- gem.add_runtime_dependency 'couchbase-model' # couchbase active model orm
20
- end
21
16
  gem.add_runtime_dependency 'radix' # This converts numbers to the unicode representation
22
17
 
23
18
  gem.add_development_dependency 'rspec', '>= 2.14'
@@ -1,116 +1,116 @@
1
- #
2
- # This disables the built in generator, faster then running validations twice
3
- # Forces models to include an ID generator
4
- #
5
- module Couchbase
6
- class Model
7
- class UUID
8
- def initialize(*args)
9
-
10
- end
11
-
12
- def next(*args)
13
- nil
14
- end
15
- end
16
- end
17
- end
18
-
19
- #
20
- # This is our id generator, runs in the before save call back
21
- #
22
- module CouchbaseId
23
-
24
- # NOTE:: incr, decr, append, prepend == atomic
25
- module Generator
26
-
27
-
28
- # Basic compression using UTF (more efficient for ID's stored as strings)
29
- B65 = Radix::Base.new(Radix::BASE::B62 + ['-', '_', '~'])
30
- B10 = Radix::Base.new(10)
31
-
32
- # The cluster id this node belongs to (avoids XDCR clashes)
33
- CLUSTER_ID ||= ENV['COUCHBASE_CLUSTER'] || 1 # Cluster ID number
34
-
35
- # instance method
36
- def generate_id
37
- if self.id.nil?
38
- #
39
- # Generate the id (incrementing values as required)
40
- #
41
- overflow = self.class.__overflow__ ||= self.class.bucket.get("#{self.class.design_document}:#{CLUSTER_ID}:overflow", :quiet => true) # Don't error if not there
42
- count = self.class.bucket.incr("#{self.class.design_document}:#{CLUSTER_ID}:count", :create => true) # This models current id count
43
- if count == 0 || overflow.nil?
44
- overflow ||= 0
45
- overflow += 1
46
- # We shouldn't need to worry about concurrency here due to the size of count
47
- # Would require ~18446744073709551615 concurrent writes
48
- self.class.bucket.set("#{self.class.design_document}:#{CLUSTER_ID}:overflow", overflow)
49
- self.class.__overflow__ = overflow
50
- end
51
-
52
- self.id = self.class.__class_id_generator__.call(overflow, count)
53
-
54
-
55
- #
56
- # So an existing id would only be present if:
57
- # => something crashed before incrementing the overflow
58
- # => this is another request was occurring before the overflow is incremented
59
- #
60
- # Basically only the overflow should be able to cause issues, we'll increment the count just to be sure
61
- # One would hope this code only ever runs under high load during an overflow event
62
- #
63
- while self.class.bucket.get(self.id, :quiet => true).present?
64
- # Set in-case we are here due to a crash (concurrency is not an issue)
65
- # Note we are not incrementing the @__overflow__ variable
66
- self.class.bucket.set("#{self.class.design_document}:#{CLUSTER_ID}:overflow", overflow + 1)
67
- count = self.class.bucket.incr("#{self.class.design_document}:#{CLUSTER_ID}:count") # Increment just in case (attempt to avoid infinite loops)
68
-
69
- # Reset the overflow
70
- if self.class.__overflow__ == overflow
71
- self.class.__overflow__ = nil
72
- end
73
-
74
- # Generate the new id
75
- self.id = self.class.__class_id_generator__.call(overflow + 1, count)
76
- end
77
- end
78
- end
79
-
80
- def self.included(base)
81
- class << base
82
- attr_accessor :__overflow__
83
- attr_accessor :__class_id_generator__
84
- end
85
-
86
-
87
- base.class_eval do
88
- #
89
- # Best case we have 18446744073709551615 * 18446744073709551615 model entries for each database cluster
90
- # and we can always change the cluster id if this limit is reached
91
- #
92
- define_model_callbacks :save, :create
93
- before_save :generate_id
94
- before_create :generate_id
95
-
96
- def self.default_class_id_generator(overflow, count)
97
- id = Radix.convert([overflow, CLUSTER_ID].join.to_i, B10, B65) + Radix.convert(count, B10, B65)
98
- "#{self.design_document}-#{id}"
99
- end
100
-
101
- #
102
- # Override the default hashing function
103
- #
104
- def self.set_class_id_generator(callback = nil, &block)
105
- callback ||= block
106
- self.__class_id_generator__ = callback
107
- end
108
-
109
- #
110
- # Configure class level variables
111
- base.__overflow__ = nil
112
- base.__class_id_generator__ = method(:default_class_id_generator)
113
- end
114
- end
115
- end # END:: Generator
116
- end
1
+ #
2
+ # This disables the built in generator, faster then running validations twice
3
+ # Forces models to include an ID generator
4
+ #
5
+ module Couchbase
6
+ class Model
7
+ class UUID
8
+ def initialize(*args)
9
+
10
+ end
11
+
12
+ def next(*args)
13
+ nil
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ #
20
+ # This is our id generator, runs in the before save call back
21
+ #
22
+ module CouchbaseId
23
+
24
+ # NOTE:: incr, decr, append, prepend == atomic
25
+ module Generator
26
+
27
+
28
+ # Basic compression using UTF (more efficient for ID's stored as strings)
29
+ B65 = Radix::Base.new(Radix::BASE::B62 + ['-', '_', '~'])
30
+ B10 = Radix::Base.new(10)
31
+
32
+ # The cluster id this node belongs to (avoids XDCR clashes)
33
+ CLUSTER_ID ||= ENV['COUCHBASE_CLUSTER'] || 1 # Cluster ID number
34
+
35
+ # instance method
36
+ def generate_id
37
+ if self.id.nil?
38
+ #
39
+ # Generate the id (incrementing values as required)
40
+ #
41
+ overflow = self.class.__overflow__ ||= self.class.bucket.get("#{self.class.design_document}:#{CLUSTER_ID}:overflow", :quiet => true) # Don't error if not there
42
+ count = self.class.bucket.incr("#{self.class.design_document}:#{CLUSTER_ID}:count", :create => true) # This models current id count
43
+ if count == 0 || overflow.nil?
44
+ overflow ||= 0
45
+ overflow += 1
46
+ # We shouldn't need to worry about concurrency here due to the size of count
47
+ # Would require ~18446744073709551615 concurrent writes
48
+ self.class.bucket.set("#{self.class.design_document}:#{CLUSTER_ID}:overflow", overflow)
49
+ self.class.__overflow__ = overflow
50
+ end
51
+
52
+ self.id = self.class.__class_id_generator__.call(overflow, count)
53
+
54
+
55
+ #
56
+ # So an existing id would only be present if:
57
+ # => something crashed before incrementing the overflow
58
+ # => this is another request was occurring before the overflow is incremented
59
+ #
60
+ # Basically only the overflow should be able to cause issues, we'll increment the count just to be sure
61
+ # One would hope this code only ever runs under high load during an overflow event
62
+ #
63
+ while self.class.bucket.get(self.id, :quiet => true).present?
64
+ # Set in-case we are here due to a crash (concurrency is not an issue)
65
+ # Note we are not incrementing the @__overflow__ variable
66
+ self.class.bucket.set("#{self.class.design_document}:#{CLUSTER_ID}:overflow", overflow + 1)
67
+ count = self.class.bucket.incr("#{self.class.design_document}:#{CLUSTER_ID}:count") # Increment just in case (attempt to avoid infinite loops)
68
+
69
+ # Reset the overflow
70
+ if self.class.__overflow__ == overflow
71
+ self.class.__overflow__ = nil
72
+ end
73
+
74
+ # Generate the new id
75
+ self.id = self.class.__class_id_generator__.call(overflow + 1, count)
76
+ end
77
+ end
78
+ end
79
+
80
+ def self.included(base)
81
+ class << base
82
+ attr_accessor :__overflow__
83
+ attr_accessor :__class_id_generator__
84
+ end
85
+
86
+
87
+ base.class_eval do
88
+ #
89
+ # Best case we have 18446744073709551615 * 18446744073709551615 model entries for each database cluster
90
+ # and we can always change the cluster id if this limit is reached
91
+ #
92
+ define_model_callbacks :save, :create
93
+ before_save :generate_id
94
+ before_create :generate_id
95
+
96
+ def self.default_class_id_generator(overflow, count)
97
+ id = Radix.convert([overflow, CLUSTER_ID].join.to_i, B10, B65) + Radix.convert(count, B10, B65)
98
+ "#{self.design_document}-#{id}"
99
+ end
100
+
101
+ #
102
+ # Override the default hashing function
103
+ #
104
+ def self.set_class_id_generator(callback = nil, &block)
105
+ callback ||= block
106
+ self.__class_id_generator__ = callback
107
+ end
108
+
109
+ #
110
+ # Configure class level variables
111
+ base.__overflow__ = nil
112
+ base.__class_id_generator__ = method(:default_class_id_generator)
113
+ end
114
+ end
115
+ end # END:: Generator
116
+ end
@@ -1,3 +1,3 @@
1
- module CouchbaseId
2
- VERSION = '1.0.7'
3
- end
1
+ module CouchbaseId
2
+ VERSION = '1.0.8'
3
+ end
data/lib/couchbase-id.rb CHANGED
File without changes
metadata CHANGED
@@ -1,85 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: couchbase-model
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
14
+ name: radix
22
15
  version_requirements: !ruby/object:Gem::Requirement
23
16
  requirements:
24
- - - ">="
17
+ - - '>='
25
18
  - !ruby/object:Gem::Version
26
19
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: radix
29
20
  requirement: !ruby/object:Gem::Requirement
30
21
  requirements:
31
- - - ">="
22
+ - - '>='
32
23
  - !ruby/object:Gem::Version
33
24
  version: '0'
34
- type: :runtime
35
25
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ type: :runtime
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
- requirement: !ruby/object:Gem::Requirement
29
+ version_requirements: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - '>='
46
32
  - !ruby/object:Gem::Version
47
33
  version: '2.14'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
51
35
  requirements:
52
- - - ">="
36
+ - - '>='
53
37
  - !ruby/object:Gem::Version
54
38
  version: '2.14'
39
+ prerelease: false
40
+ type: :development
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
- requirement: !ruby/object:Gem::Requirement
43
+ version_requirements: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - '>='
60
46
  - !ruby/object:Gem::Version
61
47
  version: '10.1'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
65
49
  requirements:
66
- - - ">="
50
+ - - '>='
67
51
  - !ruby/object:Gem::Version
68
52
  version: '10.1'
53
+ prerelease: false
54
+ type: :development
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: yard
71
- requirement: !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - '>='
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
62
+ requirement: !ruby/object:Gem::Requirement
79
63
  requirements:
80
- - - ">="
64
+ - - '>='
81
65
  - !ruby/object:Gem::Version
82
66
  version: '0'
67
+ prerelease: false
68
+ type: :development
83
69
  description: Overwrites the existing couchbase-model id implementation
84
70
  email:
85
71
  - steve@cotag.me
@@ -88,9 +74,9 @@ extensions: []
88
74
  extra_rdoc_files:
89
75
  - README.md
90
76
  files:
77
+ - lib/couchbase-id.rb
91
78
  - lib/couchbase-id/generator.rb
92
79
  - lib/couchbase-id/version.rb
93
- - lib/couchbase-id.rb
94
80
  - Rakefile
95
81
  - couchbase-id.gemspec
96
82
  - README.md
@@ -99,25 +85,24 @@ homepage: https://github.com/cotag/couchbase-id
99
85
  licenses:
100
86
  - MIT
101
87
  metadata: {}
102
- post_install_message:
88
+ post_install_message:
103
89
  rdoc_options: []
104
90
  require_paths:
105
91
  - lib
106
92
  required_ruby_version: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ">="
94
+ - - '>='
109
95
  - !ruby/object:Gem::Version
110
96
  version: 1.9.2
111
97
  required_rubygems_version: !ruby/object:Gem::Requirement
112
98
  requirements:
113
- - - ">="
99
+ - - '>='
114
100
  - !ruby/object:Gem::Version
115
101
  version: '0'
116
102
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.0.3
119
- signing_key:
103
+ rubyforge_project:
104
+ rubygems_version: 2.1.9
105
+ signing_key:
120
106
  specification_version: 4
121
107
  summary: Couchbase ID generator with XDCR support
122
108
  test_files: []
123
- has_rdoc: