protokoll 0.1.1 → 0.1.2
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.
- data/README.rdoc +4 -1
- data/lib/protokoll/{protokoll_auto_increment.rb → auto_increment.rb} +14 -1
- data/lib/protokoll/version.rb +1 -1
- data/lib/protokoll.rb +15 -26
- data/test/dummy/log/test.log +19077 -0
- data/test/protokoll_test.rb +22 -22
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -64,6 +64,9 @@ Ex:
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# will produce => "2011HOUSE00001", "2011HOUSE00002"...
|
67
|
-
|
67
|
+
|
68
|
+
== Questions & Sugestions
|
69
|
+
This is my _first_ public gem, so if you have any questions os sugestions, feel free to contact me (use github msg system for that). It will be awesome to hear feedback to improve the code.
|
70
|
+
|
68
71
|
|
69
72
|
This piece of software is free to use.
|
@@ -1,7 +1,20 @@
|
|
1
1
|
module Protokoll
|
2
2
|
|
3
|
-
class
|
3
|
+
class AutoIncrement
|
4
4
|
attr_accessor :options
|
5
|
+
attr_accessor :count
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@count = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def pattern=(p)
|
12
|
+
options[:pattern] = p
|
13
|
+
end
|
14
|
+
|
15
|
+
def pattern
|
16
|
+
options[:pattern]
|
17
|
+
end
|
5
18
|
|
6
19
|
def next_custom_number(column, number)
|
7
20
|
prefix(options[:pattern]).to_s +
|
data/lib/protokoll/version.rb
CHANGED
data/lib/protokoll.rb
CHANGED
@@ -1,49 +1,38 @@
|
|
1
|
-
require "protokoll/
|
1
|
+
require "protokoll/auto_increment"
|
2
2
|
require "protokoll/extract_number"
|
3
3
|
|
4
4
|
module Protokoll
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
@@
|
9
|
-
@@protokoll_auto_increment
|
10
|
-
|
11
|
-
def protokoll_count=(p)
|
12
|
-
@@protokoll_count = p
|
13
|
-
end
|
14
|
-
|
15
|
-
def protokoll_count
|
16
|
-
@@protokoll_count
|
17
|
-
end
|
8
|
+
@@protokoll = nil
|
18
9
|
|
19
|
-
def
|
20
|
-
@@
|
10
|
+
def protokoll
|
11
|
+
@@protokoll
|
21
12
|
end
|
22
13
|
|
23
|
-
def
|
24
|
-
@@
|
25
|
-
|
26
|
-
|
27
|
-
def protokoll(column, _options = {})
|
14
|
+
def protokoll(column = nil, _options = {})
|
15
|
+
@@protokoll = AutoIncrement.new if @@protokoll.nil?
|
16
|
+
return @@protokoll if column.nil?
|
17
|
+
|
28
18
|
options = { :pattern => "%Y%m#####", :number_symbol => "#"}
|
29
19
|
options.merge!(_options)
|
30
20
|
|
31
|
-
@@
|
32
|
-
|
33
|
-
|
21
|
+
@@protokoll.options = options
|
22
|
+
|
34
23
|
before_save do |record|
|
35
24
|
last = record.class.last
|
36
25
|
|
37
26
|
if last.present?
|
38
|
-
if @@
|
39
|
-
@@
|
27
|
+
if @@protokoll.outdated?(last)
|
28
|
+
@@protokoll.count = 0
|
40
29
|
else
|
41
|
-
@@
|
30
|
+
@@protokoll.count = ExtractNumber.number(last[column], options[:pattern])
|
42
31
|
end
|
43
32
|
end
|
44
33
|
|
45
|
-
@@
|
46
|
-
record[column] = @@
|
34
|
+
@@protokoll.count += 1
|
35
|
+
record[column] = @@protokoll.next_custom_number(column, @@protokoll.count)
|
47
36
|
end
|
48
37
|
end
|
49
38
|
end
|