auto_increment 1.3.0 → 1.4.0

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: de47f750eacb36eb55191fedfa48c4171fbb76c9
4
- data.tar.gz: 19e51a34cb362de1f4e7943f53c46725cc0e4965
3
+ metadata.gz: 564b658b6b2444141f7eb814e2125c480c06301c
4
+ data.tar.gz: ef6c4950e669707eac1d8f97a63e627708db2e2f
5
5
  SHA512:
6
- metadata.gz: 4ee67e7884c39f127c8df23b6bbd25b25ceee9b6de60a81c328f79d1ed191a61efdd07980afd0a8e4476c7333ee22e89e7d31007a65fc8a0ccfac042fee68b9e
7
- data.tar.gz: ba0e2b25e96905833c11b9d4be7f00de95e2bbeda2fe15693adf3c5ab78c3260d5309628f8655a4f006877e8a6e34098cf6e2d0c0ad8e4ef59aae4e6c405aa03
6
+ metadata.gz: 7792a1be4db338672e977040591fcd57a3229da7b35f54fed2e2c04dcafadd2b1f659a4512eefbb0e14888eed60db9fcbabe3553c18c24a6f49600f0d24ec053
7
+ data.tar.gz: a401806c20c58968755790e1231b5ce5f9a1490507b8e37cdb60e20670d0c9b9fe493c1d8125a637a10b91a76bd375e7278c5884629577a997e4433ccdcaa401
data/README.md CHANGED
@@ -38,7 +38,7 @@ And your code field will be incremented
38
38
 
39
39
  So you have a different column or need a scope. auto_increment provides options. You can use it like this:
40
40
 
41
- auto_increment :letter, scope: [:account_id, :job_id], initial: 'C', force: true, lock: false
41
+ auto_increment :letter, scope: [:account_id, :job_id], initial: 'C', force: true, lock: false, before: :create
42
42
 
43
43
  First argument is the column that will be incremented. Can be integer or string.
44
44
 
@@ -46,6 +46,7 @@ First argument is the column that will be incremented. Can be integer or string.
46
46
  * initial: initial value of column (default: 1)
47
47
  * force: you can set a value before create and auto_increment will not change that, but if you do want this, set force to true (default: false)
48
48
  * lock: you can set a lock on the max query. (default: false)
49
+ * before: you can choose a different callback to be used (:create, :save, :validation) (default: create)
49
50
 
50
51
 
51
52
  ## Compatibility
@@ -6,7 +6,11 @@ module AutoIncrement
6
6
  # +AutoIncrement::ActiveRecord::ClassMethods+
7
7
  module ClassMethods
8
8
  def auto_increment(column = nil, options = {})
9
- before_create Incrementor.new(column, options)
9
+ options.reverse_merge! before: :create
10
+
11
+ callback = "before_#{ options[:before]}"
12
+
13
+ self.send callback, Incrementor.new(column, options)
10
14
  end
11
15
  end
12
16
  end
@@ -18,6 +18,9 @@ module AutoIncrement
18
18
  write if can_write?
19
19
  end
20
20
 
21
+ alias_method :before_validation, :before_create
22
+ alias_method :before_save, :before_create
23
+
21
24
  private
22
25
 
23
26
  def can_write?
@@ -1,4 +1,4 @@
1
1
  # +AutoIncrement::VERSION+
2
2
  module AutoIncrement
3
- VERSION = '1.3.0'
3
+ VERSION = '1.4.0'
4
4
  end
Binary file
@@ -53,4 +53,13 @@ describe AutoIncrement do
53
53
  it { expect(@accounts.size).to eq 25 }
54
54
  it { expect(account_last_letter_code).to eq 'Y' }
55
55
  end
56
+
57
+
58
+ describe 'set before validation' do
59
+ account3 = Account.new
60
+ account3.valid?
61
+
62
+ it { expect(account3.code).not_to be_nil }
63
+ end
64
+
56
65
  end
@@ -1,6 +1,6 @@
1
1
  # Spec +Account+
2
2
  class Account < ActiveRecord::Base
3
- auto_increment :code
3
+ auto_increment :code, before: :validation
4
4
 
5
5
  has_many :users
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_increment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Diesel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord