protokoll 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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 ProtokollAutoIncrement
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 +
@@ -1,3 +1,3 @@
1
1
  module Protokoll
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/protokoll.rb CHANGED
@@ -1,49 +1,38 @@
1
- require "protokoll/protokoll_auto_increment"
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
- @@protokoll_count = 0
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 protokoll_pattern=(p)
20
- @@protokoll_auto_increment.options[:pattern] = p
10
+ def protokoll
11
+ @@protokoll
21
12
  end
22
13
 
23
- def protokoll_pattern
24
- @@protokoll_auto_increment.options[:pattern]
25
- end
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
- @@protokoll_auto_increment = ProtokollAutoIncrement.new
32
- @@protokoll_auto_increment.options = options
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 @@protokoll_auto_increment.outdated?(last)
39
- @@protokoll_count = 0
27
+ if @@protokoll.outdated?(last)
28
+ @@protokoll.count = 0
40
29
  else
41
- @@protokoll_count = ExtractNumber.number(last[column], options[:pattern])
30
+ @@protokoll.count = ExtractNumber.number(last[column], options[:pattern])
42
31
  end
43
32
  end
44
33
 
45
- @@protokoll_count += 1
46
- record[column] = @@protokoll_auto_increment.next_custom_number(column, @@protokoll_count)
34
+ @@protokoll.count += 1
35
+ record[column] = @@protokoll.next_custom_number(column, @@protokoll.count)
47
36
  end
48
37
  end
49
38
  end