protokoll 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/protokoll/counter.rb +1 -1
- data/lib/protokoll/protokoll.rb +8 -0
- data/lib/protokoll/version.rb +1 -1
- data/test/protokoll_test.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd0f2c68950237c7a6e046e5b71eb626b1153e42
|
4
|
+
data.tar.gz: 23de0d9139dd69f36e811f4499ebaab8a9c035b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 399235e68180d984694573b3d5bab1851d45570f025d6aa8a8348911aa28ecd10e5d4ea1fe80f05ab95d198630972303198595eff8572ed22245c75e8fddd85d
|
7
|
+
data.tar.gz: 5ae6f2301708d32706c7b5d13b1d57d1abb77b3cacfc30385f0c0a33ea317f77ceb13a5b5e86b7593322f2e396b77139942dd5567599f2b265229ab50736d062
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
## Description
|
5
5
|
|
6
|
-
Protokoll is a simple Rails 4 pluggin to simplify the management of a custom autoincrement value for a model.
|
6
|
+
Protokoll is a simple Rails 4 pluggin to simplify the management of a custom autoincrement value for a model.
|
7
7
|
|
8
8
|
If you want to create an autoincrement information on the database, just like those callcenter registration number (2011000001, 2011000002, 20110000003 and on) this gem is for you! If you want to create just an custom autoincrement value, this gem is for you too! =)
|
9
9
|
|
@@ -53,13 +53,13 @@ Or use any time based format. You can use in the pattern any combination of:
|
|
53
53
|
|
54
54
|
```ruby
|
55
55
|
# assume it's 2011/01/01 12:00
|
56
|
-
"%Y" for year # => appends 2011
|
57
|
-
"%y" for year # => appends 11
|
56
|
+
"%Y" for year # => appends 2011
|
57
|
+
"%y" for year # => appends 11
|
58
58
|
"%m" for month # => appends 01
|
59
59
|
"%d" for day # => appends 01
|
60
60
|
"%H" for hour # => appends 12
|
61
61
|
"%M" for minute # => appends 00
|
62
|
-
"#" for the autoincrement number (use
|
62
|
+
"#" for the autoincrement number (use as long as you want)
|
63
63
|
```
|
64
64
|
|
65
65
|
Using the Time formating string ("%y", "%m", ...) is totally optional. It's fine to use "CALL####", "BUY###N" or any combination you like.
|
@@ -71,7 +71,7 @@ class Car < ActiveRecord::Base
|
|
71
71
|
protokoll :number, :pattern => "CAR%y#####"
|
72
72
|
end
|
73
73
|
|
74
|
-
# will produce => "CAR1100001", "CAR1100002"...
|
74
|
+
# will produce => "CAR1100001", "CAR1100002"...
|
75
75
|
|
76
76
|
# :sell_number must be a String
|
77
77
|
class House < ActiveRecord::Base
|
@@ -103,7 +103,7 @@ It just increases the counter so any other object that gets saved or uses the #r
|
|
103
103
|
## Installation
|
104
104
|
|
105
105
|
Just add to the Gemfile:
|
106
|
-
|
106
|
+
|
107
107
|
```ruby
|
108
108
|
gem 'protokoll'
|
109
109
|
```
|
data/lib/protokoll/counter.rb
CHANGED
@@ -19,7 +19,7 @@ module Protokoll
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def self.outdated?(record, options)
|
22
|
-
Time.now.strftime(update_event(options)).to_i > record.updated_at.strftime(update_event(options)).to_i
|
22
|
+
Time.now.utc.strftime(update_event(options)).to_i > record.updated_at.strftime(update_event(options)).to_i
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.update_event(options)
|
data/lib/protokoll/protokoll.rb
CHANGED
@@ -17,6 +17,8 @@ module Protokoll
|
|
17
17
|
:start => 0 }
|
18
18
|
|
19
19
|
options.merge!(_options)
|
20
|
+
raise ArgumentError.new("pattern can't be nil!") if options[:pattern].nil?
|
21
|
+
raise ArgumentError.new("pattern requires at least one counter symbol #{options[:number_symbol]}") unless pattern_includes_symbols?(options)
|
20
22
|
|
21
23
|
# Defining custom method
|
22
24
|
send :define_method, "reserve_#{options[:column]}!".to_sym do
|
@@ -30,6 +32,12 @@ module Protokoll
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def pattern_includes_symbols?(options)
|
39
|
+
options[:pattern].count(options[:number_symbol]) > 0
|
40
|
+
end
|
33
41
|
end
|
34
42
|
|
35
43
|
end
|
data/lib/protokoll/version.rb
CHANGED
data/test/protokoll_test.rb
CHANGED
@@ -388,6 +388,24 @@ class ProtokollTest < ActiveSupport::TestCase
|
|
388
388
|
assert_equal "2011092601", protocol3.number
|
389
389
|
end
|
390
390
|
|
391
|
+
test "rejects empty patterns" do
|
392
|
+
|
393
|
+
assert_raise ArgumentError do
|
394
|
+
class Protocol < ActiveRecord::Base
|
395
|
+
protokoll :number, :pattern => nil
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
test "rejects invalid patterns" do
|
401
|
+
|
402
|
+
assert_raise ArgumentError do
|
403
|
+
class Protocol < ActiveRecord::Base
|
404
|
+
protokoll :number, :pattern => "%ydodgyPattern"
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
391
409
|
end
|
392
410
|
|
393
411
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protokoll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Celso Dantas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|