couchbase-id 1.0.3 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ad6585c5467f6033260f1ec187e753ecc91208f
4
- data.tar.gz: 68f6f9aa0fd6d3241b14a500455fb42463ade10c
3
+ metadata.gz: 76cad00122eedaa52d97d989e130faff4a9ce0eb
4
+ data.tar.gz: c1883158b04f85e3315814b54a69cb2d7db801a5
5
5
  SHA512:
6
- metadata.gz: 960510c878e491bb88f1035ca7e06d01517284bf347362b030082850feee1bc71bec5a85fcabc5b5d4914883f279df882b21a256cf53f064c87628268a29fc1f
7
- data.tar.gz: 959d532e9d72242eb036a39eed10f147cc19dd3b02ef44fa8affba4f41d4bcf47cfe2ddbc5edbcae7b36f381ad0223f849d96f47c6ee0309ede20ca333499693
6
+ metadata.gz: 62176c3dc63b501089916f75761c6a715589f026f90eac885c01873c1b1109f6dc49d2797e418faaa93aceb0741deddb8454fadc1af08ff621e1082a3f5468e1
7
+ data.tar.gz: 5ccba7537d9cb5b6cc72b4594154af643c14fc92d679b69da2fe976f7bc7da7f05b66aa38dcf37dffe10567525f0568c79a4e4c951ab7019448df4b949e5a6b7
@@ -38,18 +38,18 @@ module CouchbaseId
38
38
  #
39
39
  # Generate the id (incrementing values as required)
40
40
  #
41
- overflow = @@__overflow__ ||= self.class.bucket.get("#{@@__class_name__}:#{CLUSTER_ID}:overflow", :quiet => true) # Don't error if not there
42
- count = self.class.bucket.incr("#{@@__class_name__}:#{CLUSTER_ID}:count", :create => true) # This models current id count
41
+ overflow = self.class.__overflow__ ||= self.class.bucket.get("#{self.class.__class_name__}:#{CLUSTER_ID}:overflow", :quiet => true) # Don't error if not there
42
+ count = self.class.bucket.incr("#{self.class.__class_name__}:#{CLUSTER_ID}:count", :create => true) # This models current id count
43
43
  if count == 0 || overflow.nil?
44
44
  overflow ||= 0
45
45
  overflow += 1
46
46
  # We shouldn't need to worry about concurrency here due to the size of count
47
47
  # Would require ~18446744073709551615 concurrent writes
48
- self.class.bucket.set("#{@@__class_name__}:#{CLUSTER_ID}:overflow", overflow)
49
- @@__overflow__ = overflow
48
+ self.class.bucket.set("#{self.class.__class_name__}:#{CLUSTER_ID}:overflow", overflow)
49
+ self.class.__overflow__ = overflow
50
50
  end
51
51
 
52
- self.id = @@__class_id_generator__.call(overflow, count)
52
+ self.id = self.class.__class_id_generator__.call(overflow, count)
53
53
 
54
54
 
55
55
  #
@@ -63,21 +63,28 @@ module CouchbaseId
63
63
  while self.class.bucket.get(self.id, :quiet => true).present?
64
64
  # Set in-case we are here due to a crash (concurrency is not an issue)
65
65
  # Note we are not incrementing the @__overflow__ variable
66
- self.class.bucket.set("#{@@__class_name__}:#{CLUSTER_ID}:overflow", overflow + 1)
67
- count = self.class.bucket.incr("#{@@__class_name__}:#{CLUSTER_ID}:count") # Increment just in case (attempt to avoid infinite loops)
66
+ self.class.bucket.set("#{self.class.__class_name__}:#{CLUSTER_ID}:overflow", overflow + 1)
67
+ count = self.class.bucket.incr("#{self.class.__class_name__}:#{CLUSTER_ID}:count") # Increment just in case (attempt to avoid infinite loops)
68
68
 
69
69
  # Reset the overflow
70
- if @@__overflow__ == overflow
71
- @@__overflow__ = nil
70
+ if self.class.__overflow__ == overflow
71
+ self.class.__overflow__ = nil
72
72
  end
73
73
 
74
74
  # Generate the new id
75
- self.id = @@__class_id_generator__.call(overflow + 1, count)
75
+ self.id = self.class.__class_id_generator__.call(overflow + 1, count)
76
76
  end
77
77
  end
78
78
  end
79
79
 
80
80
  def self.included(base)
81
+ class << base
82
+ attr_accessor :__overflow__
83
+ attr_accessor :__class_id_generator__
84
+ attr_accessor :__class_name__
85
+ end
86
+
87
+
81
88
  base.class_eval do
82
89
  #
83
90
  # Best case we have 18446744073709551615 * 18446744073709551615 model entries for each database cluster
@@ -89,7 +96,7 @@ module CouchbaseId
89
96
 
90
97
  def self.default_class_id_generator(overflow, count)
91
98
  id = Radix.convert([overflow, CLUSTER_ID].join.to_i, B10, B65) + Radix.convert(count, B10, B65)
92
- "#{@__class_name__}-#{id}"
99
+ "#{self.__class_name__}-#{id}"
93
100
  end
94
101
 
95
102
  #
@@ -97,14 +104,14 @@ module CouchbaseId
97
104
  #
98
105
  def self.set_class_id_generator(callback = nil, &block)
99
106
  callback ||= block
100
- @__class_id_generator__ = callback
107
+ self.__class_id_generator__ = callback
101
108
  end
102
109
 
103
110
  #
104
111
  # Configure class level variables
105
- @__overflow__ = nil
106
- @__class_id_generator__ = method(:default_class_id_generator)
107
- @__class_name__ = self.name.underscore.gsub(/\/|_/, '-') # The included classes name
112
+ base.__overflow__ = nil
113
+ base.__class_id_generator__ = method(:default_class_id_generator)
114
+ base.__class_name__ = self.name.underscore.gsub(/\/|_/, '-') # The included classes name
108
115
  end
109
116
  end
110
117
  end # END:: Generator
@@ -1,3 +1,3 @@
1
1
  module CouchbaseId
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach