auto_increment 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +32 -3
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/Guardfile +5 -0
- data/{README.markdown → README.md} +15 -13
- data/Rakefile +4 -13
- data/auto_increment.gemspec +30 -14
- data/lib/auto_increment.rb +13 -1
- data/lib/auto_increment/active_record.rb +5 -32
- data/lib/auto_increment/incrementor.rb +49 -0
- data/lib/auto_increment/version.rb +1 -1
- data/spec/lib/active_record_spec.rb +30 -0
- data/spec/lib/incrementor_spec.rb +25 -0
- data/spec/models/account.rb +5 -0
- data/spec/models/user.rb +5 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/active_record.rb +10 -0
- metadata +179 -32
- data/test/app/Gemfile +0 -31
- data/test/app/app/controllers/application_controller.rb +0 -3
- data/test/app/app/helpers/application_helper.rb +0 -2
- data/test/app/app/views/layouts/application.html.erb +0 -14
- data/test/app/config.ru +0 -4
- data/test/app/config/application.rb +0 -42
- data/test/app/config/boot.rb +0 -6
- data/test/app/config/environment.rb +0 -5
- data/test/app/config/environments/development.rb +0 -26
- data/test/app/config/environments/production.rb +0 -49
- data/test/app/config/environments/test.rb +0 -35
- data/test/auto_increment_test.rb +0 -66
- data/test/test_helper.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0439d87a127d0cb45c1592caac145430c05dbc59
|
4
|
+
data.tar.gz: 50e0088319d2961b17516b52f7754af6c2f4a427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01a2efcda6def8029290507fb47a4c32f3955e8240b7d43c81b17e6f44ab41b848aac306dffa37c0059cd4c547e98bd38a39dff97ed68917fa1e93ec282df384
|
7
|
+
data.tar.gz: d80e3f47ec2fafe1b0f337dba037d4269d2074d9d7a0e26884bf4370c0472c1a0791e89be0f6866a367053d1bde4e4799d56b1c6e9b60a93c5d36230f42a1128
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
@@ -1,6 +1,35 @@
|
|
1
1
|
*.gem
|
2
|
-
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
3
30
|
Gemfile.lock
|
4
|
-
|
31
|
+
.ruby-version
|
32
|
+
.ruby-gemset
|
5
33
|
|
6
|
-
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- 2.0.0
|
6
|
+
|
7
|
+
script: 'bundle exec rake'
|
8
|
+
|
9
|
+
notifications:
|
10
|
+
email:
|
11
|
+
recipients:
|
12
|
+
- felipe@29sul.com.br
|
13
|
+
- elton@29sul.com.br
|
14
|
+
on_failure: change # [always|never|change]
|
15
|
+
on_success: change # [always|never|change]
|
data/Guardfile
ADDED
@@ -1,20 +1,21 @@
|
|
1
|
-
auto_increment
|
2
|
-
==============
|
1
|
+
# auto_increment
|
3
2
|
|
4
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/felipediesel/auto_increment.svg?branch=master)](https://travis-ci.org/felipediesel/auto_increment)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/felipediesel/auto_increment/badge.svg?branch=master)](https://coveralls.io/r/felipediesel/auto_increment?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/felipediesel/auto_increment/badges/gpa.svg)](https://codeclimate.com/github/felipediesel/auto_increment)
|
5
6
|
|
6
|
-
|
7
|
-
------------
|
7
|
+
auto_increment provides automatic incrementation for a integer or string fields in Rails.
|
8
8
|
|
9
|
-
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
You can use auto_increment as a gem in Rails 4.
|
10
12
|
|
11
13
|
To use the gem version, put the following gem requirement in your `Gemfile`:
|
12
14
|
|
13
15
|
gem "auto_increment"
|
14
16
|
|
15
17
|
|
16
|
-
Usage
|
17
|
-
-----
|
18
|
+
## Usage
|
18
19
|
|
19
20
|
To work with a auto increment column you used to do sometihng like this in your model:
|
20
21
|
|
@@ -33,11 +34,11 @@ All you need to do is this:
|
|
33
34
|
And your code field will be incremented
|
34
35
|
|
35
36
|
|
36
|
-
|
37
|
+
## Customizing
|
37
38
|
|
38
39
|
So you have a different column or need a scope. auto_increment provides options. You can use it like this:
|
39
40
|
|
40
|
-
auto_increment :
|
41
|
+
auto_increment column: :letter, scope: [:account_id, :job_id], initial: 'C', force: true
|
41
42
|
|
42
43
|
* column: the column that will be incremented. Can be integer os string (default: code)
|
43
44
|
* scope: you can define columns that will be scoped and you can use as many as you want (default: nil)
|
@@ -45,9 +46,10 @@ So you have a different column or need a scope. auto_increment provides options.
|
|
45
46
|
* 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)
|
46
47
|
|
47
48
|
|
48
|
-
|
49
|
+
## Compatibility
|
50
|
+
|
51
|
+
Tested with Rails 4.0.13 in Ruby 2.0.0
|
49
52
|
|
50
|
-
|
53
|
+
## License
|
51
54
|
|
52
|
-
### License
|
53
55
|
MIT License. Copyright 2011 29sul Tecnologia da Informação <http://www.29sul.com.br/>
|
data/Rakefile
CHANGED
@@ -1,15 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
4
5
|
|
5
|
-
|
6
|
-
require 'rake/testtask'
|
7
|
-
require 'rake/rdoctask'
|
8
|
-
|
9
|
-
desc 'Run Devise unit tests.'
|
10
|
-
Rake::TestTask.new(:test) do |t|
|
11
|
-
t.libs << 'lib'
|
12
|
-
t.libs << 'test'
|
13
|
-
t.pattern = 'test/**/*_test.rb'
|
14
|
-
t.verbose = true
|
15
|
-
end
|
6
|
+
task default: :spec
|
data/auto_increment.gemspec
CHANGED
@@ -2,20 +2,36 @@
|
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
require "auto_increment/version"
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "auto_increment"
|
7
|
+
spec.version = AutoIncrement::VERSION
|
8
|
+
spec.licenses = %w(MIT)
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Felipe Diesel"]
|
11
|
+
spec.email = ["felipediesel@gmail.com"]
|
12
|
+
spec.homepage = "http://github.com/felipediesel/auto_increment"
|
13
|
+
spec.summary = %q{Auto increment a string or integer field}
|
14
|
+
spec.description = %q{Automaticaly increments a string or integer field in ActiveRecord.}
|
14
15
|
|
15
|
-
|
16
|
+
spec.rubyforge_project = "auto_increment"
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
spec.files = `git ls-files`.split("\n")
|
19
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "activerecord", "~> 4.0"
|
24
|
+
spec.add_dependency "activesupport", "~> 4.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "rspec-nc"
|
31
|
+
spec.add_development_dependency "guard"
|
32
|
+
spec.add_development_dependency "guard-rspec"
|
33
|
+
spec.add_development_dependency "fuubar"
|
34
|
+
spec.add_development_dependency "coveralls"
|
35
|
+
|
36
|
+
spec.add_development_dependency 'sqlite3'
|
21
37
|
end
|
data/lib/auto_increment.rb
CHANGED
@@ -1 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "date"
|
2
|
+
require "i18n"
|
3
|
+
require "active_record"
|
4
|
+
require "active_support"
|
5
|
+
require "active_support/time_with_zone"
|
6
|
+
require "auto_increment/version"
|
7
|
+
|
8
|
+
module AutoIncrement
|
9
|
+
autoload :Incrementor, "auto_increment/incrementor"
|
10
|
+
autoload :ActiveRecord , "auto_increment/active_record"
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveRecord::Base.send :include, AutoIncrement::ActiveRecord
|
@@ -1,38 +1,11 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
|
3
1
|
module AutoIncrement
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
options.reverse_merge! column: :code, scope: nil, initial: 1, force: false
|
8
|
-
|
9
|
-
options[:scope] = [ options[:scope] ] unless options[:scope].is_a? Array
|
10
|
-
|
11
|
-
method_name = "auto_increment_#{options[:column]}"
|
12
|
-
|
13
|
-
before_create method_name
|
14
|
-
|
15
|
-
define_method method_name do
|
16
|
-
return if send(options[:column]).present? and !options[:force]
|
2
|
+
module ActiveRecord
|
3
|
+
extend ActiveSupport::Concern
|
17
4
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if scope.present? and respond_to?(scope)
|
22
|
-
query = query.where(scope => send(scope))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
if options[:initial].class == String
|
27
|
-
max = query.select("#{options[:column]} max").order("LENGTH(#{options[:column]}) DESC, #{options[:column]} DESC").first
|
28
|
-
max = max.max if max.present?
|
29
|
-
else
|
30
|
-
max = query.maximum options[:column]
|
5
|
+
module ClassMethods
|
6
|
+
def auto_increment(options = {})
|
7
|
+
before_create Incrementor.new(options)
|
31
8
|
end
|
32
|
-
|
33
|
-
max = max.blank? ? options[:initial] : max.next
|
34
|
-
|
35
|
-
write_attribute options[:column], max
|
36
9
|
end
|
37
10
|
end
|
38
11
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module AutoIncrement
|
2
|
+
class Incrementor
|
3
|
+
def initialize(options = {})
|
4
|
+
@options = options.reverse_merge column: :code, scope: nil, initial: 1, force: false
|
5
|
+
@options[:scope] = [ @options[:scope] ] unless @options[:scope].is_a? Array
|
6
|
+
end
|
7
|
+
|
8
|
+
def before_create(record)
|
9
|
+
@record = record
|
10
|
+
write if can_write?
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def can_write?
|
16
|
+
@record.send(@options[:column]).blank? or @options[:force]
|
17
|
+
end
|
18
|
+
|
19
|
+
def write
|
20
|
+
@record.send :write_attribute, @options[:column], increment
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_scopes(query)
|
24
|
+
@options[:scope].each do |scope|
|
25
|
+
if scope.present? and @record.respond_to?(scope)
|
26
|
+
query = query.where(scope => @record.send(scope))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
query
|
31
|
+
end
|
32
|
+
|
33
|
+
def maximum
|
34
|
+
query = build_scopes @record.class
|
35
|
+
|
36
|
+
if @options[:initial].class == String
|
37
|
+
query.select("#{@options[:column]} max").order("LENGTH(#{@options[:column]}) DESC, #{@options[:column]} DESC").first.try :max
|
38
|
+
else
|
39
|
+
query.maximum @options[:column]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def increment
|
44
|
+
max = maximum
|
45
|
+
|
46
|
+
max.blank? ? @options[:initial] : max.next
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'models/account'
|
3
|
+
require 'models/user'
|
4
|
+
|
5
|
+
describe AutoIncrement do
|
6
|
+
before :all do
|
7
|
+
@account1 = Account.create name: 'My Account'
|
8
|
+
@account2 = Account.create name: 'Another Account', code: 50
|
9
|
+
|
10
|
+
@user_account1 = @account1.users.create name: 'Felipe', letter_code: 'Z'
|
11
|
+
@user_account2 = @account2.users.create name: 'Daniel'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'initial' do
|
15
|
+
it { expect(@account1.code).to eq 1 }
|
16
|
+
it { expect(@user_account1.letter_code).to eq 'A' }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "do not increment outside scope" do
|
20
|
+
it { expect(@user_account2.letter_code).to eq 'A' }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "not set column if is already set" do
|
24
|
+
it { expect(@account2.code).to eq 50 }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "set column if option force is used" do
|
28
|
+
it { expect(@user_account1.letter_code).to eq 'A' }
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AutoIncrement::Incrementor do
|
4
|
+
{
|
5
|
+
nil => 1, 0 => 1, 1 => 2, 'A' => 'B', 'Z' => 'AA', 'AA' => 'AB', 'AAAAA' => 'AAAAB'
|
6
|
+
}.each do |previous_value, next_value|
|
7
|
+
describe "increment value for #{previous_value}" do
|
8
|
+
it {
|
9
|
+
allow(subject).to receive(:maximum) { previous_value }
|
10
|
+
expect(subject.send(:increment)).to eq next_value
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "initial value of string" do
|
16
|
+
subject {
|
17
|
+
AutoIncrement::Incrementor.new initial: 'A'
|
18
|
+
}
|
19
|
+
|
20
|
+
it {
|
21
|
+
allow(subject).to receive(:maximum) { nil }
|
22
|
+
expect(subject.send(:increment)).to eq 'A'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
data/spec/models/user.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,15 +1,169 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_increment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.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:
|
12
|
-
dependencies:
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-nc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: fuubar
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sqlite3
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
13
167
|
description: Automaticaly increments a string or integer field in ActiveRecord.
|
14
168
|
email:
|
15
169
|
- felipediesel@gmail.com
|
@@ -17,29 +171,28 @@ executables: []
|
|
17
171
|
extensions: []
|
18
172
|
extra_rdoc_files: []
|
19
173
|
files:
|
174
|
+
- .coveralls.yml
|
20
175
|
- .gitignore
|
176
|
+
- .rspec
|
177
|
+
- .travis.yml
|
21
178
|
- Gemfile
|
22
|
-
-
|
179
|
+
- Guardfile
|
180
|
+
- README.md
|
23
181
|
- Rakefile
|
24
182
|
- auto_increment.gemspec
|
25
183
|
- lib/auto_increment.rb
|
26
184
|
- lib/auto_increment/active_record.rb
|
185
|
+
- lib/auto_increment/incrementor.rb
|
27
186
|
- lib/auto_increment/version.rb
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
- test/app/config/boot.rb
|
35
|
-
- test/app/config/environment.rb
|
36
|
-
- test/app/config/environments/development.rb
|
37
|
-
- test/app/config/environments/production.rb
|
38
|
-
- test/app/config/environments/test.rb
|
39
|
-
- test/auto_increment_test.rb
|
40
|
-
- test/test_helper.rb
|
187
|
+
- spec/lib/active_record_spec.rb
|
188
|
+
- spec/lib/incrementor_spec.rb
|
189
|
+
- spec/models/account.rb
|
190
|
+
- spec/models/user.rb
|
191
|
+
- spec/spec_helper.rb
|
192
|
+
- spec/support/active_record.rb
|
41
193
|
homepage: http://github.com/felipediesel/auto_increment
|
42
|
-
licenses:
|
194
|
+
licenses:
|
195
|
+
- MIT
|
43
196
|
metadata: {}
|
44
197
|
post_install_message:
|
45
198
|
rdoc_options: []
|
@@ -57,21 +210,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
210
|
version: '0'
|
58
211
|
requirements: []
|
59
212
|
rubyforge_project: auto_increment
|
60
|
-
rubygems_version: 2.
|
213
|
+
rubygems_version: 2.4.4
|
61
214
|
signing_key:
|
62
215
|
specification_version: 4
|
63
216
|
summary: Auto increment a string or integer field
|
64
217
|
test_files:
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
|
72
|
-
- test/app/config/environment.rb
|
73
|
-
- test/app/config/environments/development.rb
|
74
|
-
- test/app/config/environments/production.rb
|
75
|
-
- test/app/config/environments/test.rb
|
76
|
-
- test/auto_increment_test.rb
|
77
|
-
- test/test_helper.rb
|
218
|
+
- spec/lib/active_record_spec.rb
|
219
|
+
- spec/lib/incrementor_spec.rb
|
220
|
+
- spec/models/account.rb
|
221
|
+
- spec/models/user.rb
|
222
|
+
- spec/spec_helper.rb
|
223
|
+
- spec/support/active_record.rb
|
224
|
+
has_rdoc:
|
data/test/app/Gemfile
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
source 'http://rubygems.org'
|
2
|
-
|
3
|
-
gem 'rails', '3.0.4'
|
4
|
-
|
5
|
-
# Bundle edge Rails instead:
|
6
|
-
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
-
|
8
|
-
gem 'sqlite3'
|
9
|
-
|
10
|
-
# Use unicorn as the web server
|
11
|
-
# gem 'unicorn'
|
12
|
-
|
13
|
-
# Deploy with Capistrano
|
14
|
-
# gem 'capistrano'
|
15
|
-
|
16
|
-
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
17
|
-
# gem 'ruby-debug'
|
18
|
-
# gem 'ruby-debug19'
|
19
|
-
|
20
|
-
# Bundle the extra gems:
|
21
|
-
# gem 'bj'
|
22
|
-
# gem 'nokogiri'
|
23
|
-
# gem 'sqlite3-ruby', :require => 'sqlite3'
|
24
|
-
# gem 'aws-s3', :require => 'aws/s3'
|
25
|
-
|
26
|
-
# Bundle gems for the local environment. Make sure to
|
27
|
-
# put test-only gems in this group so their generators
|
28
|
-
# and rake tasks are available in development mode:
|
29
|
-
# group :development, :test do
|
30
|
-
# gem 'webrat'
|
31
|
-
# end
|
data/test/app/config.ru
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require 'rails/all'
|
4
|
-
|
5
|
-
# If you have a Gemfile, require the gems listed there, including any gems
|
6
|
-
# you've limited to :test, :development, or :production.
|
7
|
-
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
8
|
-
|
9
|
-
module App
|
10
|
-
class Application < Rails::Application
|
11
|
-
# Settings in config/environments/* take precedence over those specified here.
|
12
|
-
# Application configuration should go into files in config/initializers
|
13
|
-
# -- all .rb files in that directory are automatically loaded.
|
14
|
-
|
15
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
16
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
17
|
-
|
18
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
19
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
20
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
21
|
-
|
22
|
-
# Activate observers that should always be running.
|
23
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
24
|
-
|
25
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
26
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
27
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
28
|
-
|
29
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
30
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
31
|
-
# config.i18n.default_locale = :de
|
32
|
-
|
33
|
-
# JavaScript files you want as :defaults (application.js is always included).
|
34
|
-
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
35
|
-
|
36
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
37
|
-
config.encoding = "utf-8"
|
38
|
-
|
39
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
40
|
-
config.filter_parameters += [:password]
|
41
|
-
end
|
42
|
-
end
|
data/test/app/config/boot.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
App::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# In the development environment your application's code is reloaded on
|
5
|
-
# every request. This slows down response time but is perfect for development
|
6
|
-
# since you don't have to restart the webserver when you make code changes.
|
7
|
-
config.cache_classes = false
|
8
|
-
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
11
|
-
|
12
|
-
# Show full error reports and disable caching
|
13
|
-
config.consider_all_requests_local = true
|
14
|
-
config.action_view.debug_rjs = true
|
15
|
-
config.action_controller.perform_caching = false
|
16
|
-
|
17
|
-
# Don't care if the mailer can't send
|
18
|
-
config.action_mailer.raise_delivery_errors = false
|
19
|
-
|
20
|
-
# Print deprecation notices to the Rails logger
|
21
|
-
config.active_support.deprecation = :log
|
22
|
-
|
23
|
-
# Only use best-standards-support built into browsers
|
24
|
-
config.action_dispatch.best_standards_support = :builtin
|
25
|
-
end
|
26
|
-
|
@@ -1,49 +0,0 @@
|
|
1
|
-
App::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The production environment is meant for finished, "live" apps.
|
5
|
-
# Code is not reloaded between requests
|
6
|
-
config.cache_classes = true
|
7
|
-
|
8
|
-
# Full error reports are disabled and caching is turned on
|
9
|
-
config.consider_all_requests_local = false
|
10
|
-
config.action_controller.perform_caching = true
|
11
|
-
|
12
|
-
# Specifies the header that your server uses for sending files
|
13
|
-
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
-
|
15
|
-
# For nginx:
|
16
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
-
|
18
|
-
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
-
# just comment this out and Rails will serve the files
|
20
|
-
|
21
|
-
# See everything in the log (default is :info)
|
22
|
-
# config.log_level = :debug
|
23
|
-
|
24
|
-
# Use a different logger for distributed setups
|
25
|
-
# config.logger = SyslogLogger.new
|
26
|
-
|
27
|
-
# Use a different cache store in production
|
28
|
-
# config.cache_store = :mem_cache_store
|
29
|
-
|
30
|
-
# Disable Rails's static asset server
|
31
|
-
# In production, Apache or nginx will already do this
|
32
|
-
config.serve_static_assets = false
|
33
|
-
|
34
|
-
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
-
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
-
|
37
|
-
# Disable delivery errors, bad email addresses will be ignored
|
38
|
-
# config.action_mailer.raise_delivery_errors = false
|
39
|
-
|
40
|
-
# Enable threaded mode
|
41
|
-
# config.threadsafe!
|
42
|
-
|
43
|
-
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
-
# the I18n.default_locale when a translation can not be found)
|
45
|
-
config.i18n.fallbacks = true
|
46
|
-
|
47
|
-
# Send deprecation notices to registered listeners
|
48
|
-
config.active_support.deprecation = :notify
|
49
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
App::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The test environment is used exclusively to run your application's
|
5
|
-
# test suite. You never need to work with it otherwise. Remember that
|
6
|
-
# your test database is "scratch space" for the test suite and is wiped
|
7
|
-
# and recreated between test runs. Don't rely on the data there!
|
8
|
-
config.cache_classes = true
|
9
|
-
|
10
|
-
# Log error messages when you accidentally call methods on nil.
|
11
|
-
config.whiny_nils = true
|
12
|
-
|
13
|
-
# Show full error reports and disable caching
|
14
|
-
config.consider_all_requests_local = true
|
15
|
-
config.action_controller.perform_caching = false
|
16
|
-
|
17
|
-
# Raise exceptions instead of rendering exception templates
|
18
|
-
config.action_dispatch.show_exceptions = false
|
19
|
-
|
20
|
-
# Disable request forgery protection in test environment
|
21
|
-
config.action_controller.allow_forgery_protection = false
|
22
|
-
|
23
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
-
# The :test delivery method accumulates sent emails in the
|
25
|
-
# ActionMailer::Base.deliveries array.
|
26
|
-
config.action_mailer.delivery_method = :test
|
27
|
-
|
28
|
-
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
-
# like if you have constraints or database-specific column types
|
31
|
-
# config.active_record.schema_format = :sql
|
32
|
-
|
33
|
-
# Print deprecation notices to the stderr
|
34
|
-
config.active_support.deprecation = :stderr
|
35
|
-
end
|
data/test/auto_increment_test.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
4
|
-
|
5
|
-
class AutoIncrementActiveRecordTest < ActiveRecord::TestCase
|
6
|
-
def setup
|
7
|
-
@account1 = Account.create :name => 'My Account'
|
8
|
-
@account2 = Account.create :name => 'My Second Account'
|
9
|
-
@user1 = @account1.users.create :name => 'Felipe'
|
10
|
-
@user2 = @account1.users.create :name => 'Sabrina'
|
11
|
-
|
12
|
-
@user_account2 = @account2.users.create :name => 'Daniel'
|
13
|
-
|
14
|
-
@user3 = @account1.users.create :name => 'Paulo'
|
15
|
-
@user3.letter_code = 'Z'
|
16
|
-
@user3.save
|
17
|
-
|
18
|
-
@user4 = @account1.users.create :name => 'Marlene'
|
19
|
-
@user4.save
|
20
|
-
|
21
|
-
@user5 = @account1.users.create :name => 'Patricia'
|
22
|
-
@user5.save
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
test "use initial" do
|
27
|
-
assert_equal 1, @account1.code
|
28
|
-
|
29
|
-
assert_equal 'A', @user1.letter_code
|
30
|
-
end
|
31
|
-
|
32
|
-
test "increments numbers" do
|
33
|
-
assert_equal 2, @account2.code
|
34
|
-
end
|
35
|
-
|
36
|
-
test "increments letters" do
|
37
|
-
assert_equal 'B', @user2.letter_code
|
38
|
-
end
|
39
|
-
|
40
|
-
test "do not increment outside scope" do
|
41
|
-
assert_equal 'A', @user_account2.letter_code
|
42
|
-
end
|
43
|
-
|
44
|
-
test "Z increments to AA" do
|
45
|
-
assert_equal 'AA', @user4.letter_code
|
46
|
-
end
|
47
|
-
|
48
|
-
test "AA increments to AB" do
|
49
|
-
assert_equal 'AB', @user5.letter_code
|
50
|
-
end
|
51
|
-
|
52
|
-
test "not set column if is already set" do
|
53
|
-
account = Account.new :name => 'Another Account', :code => 50
|
54
|
-
account.save
|
55
|
-
|
56
|
-
assert_equal account.code, 50
|
57
|
-
end
|
58
|
-
|
59
|
-
test "set column if option force is used" do
|
60
|
-
User.destroy_all
|
61
|
-
user = User.new :name => 'Maria', :letter_code => 'Z'
|
62
|
-
user.save
|
63
|
-
|
64
|
-
assert_equal user.letter_code, 'A'
|
65
|
-
end
|
66
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
ENV["RAILS_ENV"] = "test"
|
4
|
-
require File.expand_path('../app/config/environment', __FILE__)
|
5
|
-
require 'rails/test_help'
|
6
|
-
|
7
|
-
require File.expand_path('../../lib/auto_increment', __FILE__)
|
8
|
-
|
9
|
-
|
10
|
-
config = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
11
|
-
ActiveRecord::Base.establish_connection(config['test'])
|
12
|
-
|
13
|
-
ActiveRecord::Base.connection.create_table :accounts do |t|
|
14
|
-
t.string :name
|
15
|
-
t.date :code
|
16
|
-
end
|
17
|
-
|
18
|
-
ActiveRecord::Base.connection.create_table :users do |t|
|
19
|
-
t.string :name
|
20
|
-
t.integer :account_id
|
21
|
-
t.string :letter_code
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
class Account < ActiveRecord::Base
|
26
|
-
auto_increment
|
27
|
-
|
28
|
-
has_many :users
|
29
|
-
end
|
30
|
-
|
31
|
-
class User < ActiveRecord::Base
|
32
|
-
auto_increment :column => :letter_code, :scope => :account_id, :initial => 'A', :force => true
|
33
|
-
|
34
|
-
belongs_to :account
|
35
|
-
end
|