sequence_on 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sequence_on.rb +36 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9dade0f0bc1091023e5213837df2a1d9b1368dd
4
+ data.tar.gz: e54314af247a7851be8da0605cc5cda99b4a25fd
5
+ SHA512:
6
+ metadata.gz: 853bc40f23b4ee4f86470abf214006d353faade0e18fb2a3250035f0823b5a8a3483c04ff81bcf71cce8d87bcacf3ce794c1d6166904f43874f8362c4c3c10a4
7
+ data.tar.gz: 129ae83ed7221eb6b75e4ed84399a9bac9786e3754941919b14588c6e8bd0e8ba99586fb8e4d4512190dc2613f8b9894b97c9a71c91c01eba389cf99add2b38a
@@ -0,0 +1,36 @@
1
+ module SequencedOn
2
+ extend ActiveSupport::Concern
3
+
4
+ class_methods do
5
+
6
+ def sequence_on(l, opts={})
7
+ @@seq_on = l
8
+ @@seq_on_opts = opts
9
+ end
10
+ end
11
+
12
+ included do
13
+ before_create :generate_sequence_id, prepend: true
14
+
15
+ private
16
+
17
+ def postgresql?
18
+ defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
19
+ self.class.connection.instance_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
20
+ end
21
+
22
+ def generate_sequence_id
23
+ if postgresql?
24
+ self.class.connection.execute("LOCK TABLE #{self.class.table_name} IN EXCLUSIVE MODE")
25
+ end
26
+ last_record = self.class.class_exec(self, &@@seq_on).
27
+ order("sequential_id DESC").
28
+ first
29
+ self.sequential_id = if last_record
30
+ last_record.sequential_id + 1
31
+ else
32
+ opts[:starts_at] || 1
33
+ end
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequence_on
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy SEBAN
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Flexible acts_as_sequenced replacement
14
+ email: tech@qonto.eu
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/sequence_on.rb
20
+ homepage: https://github.com/qonto/sequence_on
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.3'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.11
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Flexible acts_as_sequenced replacement
44
+ test_files: []