sequence_generator 1.0.0 → 2.0.0

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
  SHA256:
3
- metadata.gz: 407e7974771015a92944e9a77c5c919ce254a82ecd512540d86652b35c48a465
4
- data.tar.gz: 53289d98cc4422552e31a569245481ecd2bf3ae1ae107c4efa14240525b0244d
3
+ metadata.gz: f9481e6f34a175f54749e68278599e57d698dba65f94b979f2ebff74dba7b1b3
4
+ data.tar.gz: d9eb8920884d8ed033691a35fa72f47201421e06d5078e12cc1108ab93313cc4
5
5
  SHA512:
6
- metadata.gz: bbeefa0eff497e9288cf9dcb2d3137469319f0870580bc14245c3eddeb99bb7a5eefe77dcde3061d98d85c48c6155a9c8627a4951f4b17be383aaf2760763fc8
7
- data.tar.gz: 372e2f842d7937212c18c6a681b96e340430f61e020f5e2b8e8377f56715ff0074949ba28839bfdba356378cc99b268d8135020103746bb8532ac2a057091514
6
+ metadata.gz: f8aaacccc23d8f675e8168dba094f1db665c69d235596e8c4a0425c332696ebbe3cb1ed084c15ded3165e47468cf6ee4f69d9e6eba95f13e674cf158e8a62dc3
7
+ data.tar.gz: 944b1e08f6a221754d69bcc2730508251bf907b9b51f8cd711a05fbc2933549cb58b84e548eb1321b23664aaba55c654fae23d9e92827b7ba339bc324286f70e
@@ -1,14 +1,14 @@
1
1
  module SequenceGenerator
2
2
  class CurrentSequence < ApplicationRecord
3
- validates_presence_of :name, :current, :scope
4
- validates_uniqueness_of :name, scope: :scope
3
+ validates_presence_of :name, :current, :scope, :purpose
4
+ validates_uniqueness_of :name, scope: [:scope, :purpose]
5
5
 
6
- def self.get_next_number(prefix, scope)
7
- current_sequence = CurrentSequence.lock.where(name: prefix, scope: scope).first
6
+ def self.get_next_number(prefix, scope, purpose)
7
+ current_sequence = CurrentSequence.lock.where(name: prefix, scope: scope, purpose: purpose).first
8
8
  if current_sequence
9
9
  current_sequence.update!(current: current_sequence.current + 1)
10
10
  else
11
- current_sequence = CurrentSequence.create!(name: prefix, scope: scope, current: 1)
11
+ current_sequence = CurrentSequence.create!(name: prefix, scope: scope, purpose: purpose, current: 1)
12
12
  end
13
13
  current_sequence.current
14
14
  end
@@ -40,7 +40,7 @@ module SequenceGenerator
40
40
  prefix = prefix[/#*$/] == "" ? prefix + "#####" : prefix
41
41
  digits = prefix[/#*$/].length
42
42
  prefix_without_digits = prefix.split(/#*$/)[0]
43
- next_number = CurrentSequence.get_next_number(prefix_without_digits, scope)
43
+ next_number = CurrentSequence.get_next_number(prefix_without_digits, scope, purpose)
44
44
  sequence_number = "%0#{digits}d" % (next_number).to_s
45
45
  prefix_without_digits + sequence_number
46
46
  end
@@ -0,0 +1,14 @@
1
+ class DropExtraColumnsFromSequence < ActiveRecord::Migration[5.2]
2
+ def change
3
+ remove_columns :sequence_generator_sequences,
4
+ :sequence_prefix,
5
+ :sequential_id,
6
+ :start_at,
7
+ :valid_from,
8
+ :valid_till,
9
+ :reset_from_next_year,
10
+ :financial_year_start,
11
+ :financial_year_end,
12
+ :max_prefix_number
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ class AddPurposeToCurrentSequence < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :sequence_generator_current_sequences, :purpose, :string
4
+ SequenceGenerator::Sequence.all.map do |sequence|
5
+ current_sequences = SequenceGenerator::CurrentSequence.where(scope: sequence.scope)
6
+ prefix = sequence.name.gsub(/\([^()]*?\)/) do |x|
7
+ fragment = x[1..-2]
8
+ case fragment
9
+ when "YYYY"
10
+ '(2022|2021|2020|2019|2018)'
11
+ when "YY"
12
+ '(22|21|20|19|18)'
13
+ when "IFYY"
14
+ '(21-22|20-21|19-20|18-19|17-18)'
15
+ when "IFY"
16
+ '(2122|2021|1920|1819|1718)'
17
+ when "MM"
18
+ '(01|02|03|04|05|06|07|08|09|10|11|12)'
19
+ else
20
+ '.{1,4}'
21
+ end
22
+ end
23
+ prefix = prefix.gsub('#','')
24
+ prefix = prefix + '$'
25
+
26
+ current_sequences.map do |current_sequence|
27
+ next if current_sequence.purpose
28
+ if current_sequence.name.match Regexp.new(prefix)
29
+ current_sequence.purpose = sequence.purpose
30
+ current_sequence.save!
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module SequenceGenerator
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequence_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prasann Shah
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-13 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,6 +65,8 @@ files:
65
65
  - db/migrate/20180330090901_create_sequence_generator_sequences.rb
66
66
  - db/migrate/20200412131738_add_name_to_sequence.rb
67
67
  - db/migrate/20200412131756_create_sequence_generator_current_sequences.rb
68
+ - db/migrate/20210324154416_drop_extra_columns_from_sequence.rb
69
+ - db/migrate/20210324155232_add_purpose_to_current_sequence.rb
68
70
  - lib/sequence_generator.rb
69
71
  - lib/sequence_generator/engine.rb
70
72
  - lib/sequence_generator/extender.rb
@@ -74,7 +76,7 @@ homepage: https://github.com/shipmnts/sequence_generator
74
76
  licenses:
75
77
  - MIT
76
78
  metadata: {}
77
- post_install_message:
79
+ post_install_message:
78
80
  rdoc_options: []
79
81
  require_paths:
80
82
  - lib
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  version: '0'
91
93
  requirements: []
92
94
  rubygems_version: 3.0.6
93
- signing_key:
95
+ signing_key:
94
96
  specification_version: 4
95
97
  summary: Generate sequences formatted as a string for the users
96
98
  test_files: []