sequenceid 0.0.5 → 0.0.6
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.
- data/README.md +5 -0
- data/lib/sequenceid/model_adapters/sequenceid_logic.rb +10 -2
- data/lib/sequenceid/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
|
@@ -56,6 +56,11 @@ SequenceId is compatible with Active Record **3.0**.
|
|
|
56
56
|
GET http://company1.7vals.com:3000/invoices/1
|
|
57
57
|
Get http://company2.7vals.com:3000/invoices/1
|
|
58
58
|
|
|
59
|
+
## STI
|
|
60
|
+
Supports Single Table Inheritance. Follow the above given steps in the base class, and all inherited STI classes for the model will share the sequence id generation.
|
|
61
|
+
ie If base model is Animal, and STI are Dog and Cat, then the sequence numbers will be unique to animal. Meaning given a sequence number, you could identify either
|
|
62
|
+
an animal uniquely whether it be a dog or a cat.
|
|
63
|
+
|
|
59
64
|
## Bugs
|
|
60
65
|
|
|
61
66
|
Please report them on the [Github issue tracker](http://github.com/alisyed/sequenceid/issues)
|
|
@@ -29,7 +29,7 @@ module Sequenceid
|
|
|
29
29
|
|
|
30
30
|
def reset_sequence_num
|
|
31
31
|
@save_counter||=1
|
|
32
|
-
if new_record? && @save_counter<3
|
|
32
|
+
if new_record? && valid? && @save_counter<3
|
|
33
33
|
logger.info "SEQUENCE_ID_GEM:: attempt number #{@save_counter} of a max 2"
|
|
34
34
|
self.sequence_num=relation_sequence.order("id").last.try(:sequence_num) +1
|
|
35
35
|
@save_counter+=1
|
|
@@ -40,7 +40,15 @@ module Sequenceid
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def relation_sequence
|
|
43
|
-
self.
|
|
43
|
+
resource_klass=get_sti_parent_class self.class
|
|
44
|
+
self.send(resource_klass.instance_variable_get("@parent_rel")).send(resource_klass.instance_variable_get("@current_rel"))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#for Single Table Inheritance, we need to keep going up the hierarchy until we reach the class right below ActiveRecord. Probably
|
|
48
|
+
#ought to fix this for extreme cases where models are based on a different hierarchy (monkey patch with your base model class)
|
|
49
|
+
def get_sti_parent_class(klass)
|
|
50
|
+
return klass if (klass.superclass == ActiveRecord::Base || klass.superclass==Object || klass.superclass.nil?)
|
|
51
|
+
get_sti_parent_class(klass.superclass)
|
|
44
52
|
end
|
|
45
53
|
|
|
46
54
|
end
|
data/lib/sequenceid/version.rb
CHANGED
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 0.0.
|
|
8
|
+
- 6
|
|
9
|
+
version: 0.0.6
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Syed Ali
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2012-
|
|
17
|
+
date: 2012-04-13 00:00:00 +05:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies: []
|
|
20
20
|
|