protokoll 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ module Protokoll
2
+ module ClassVariable
3
+ def self.add_to(klass, instance, options = nil)
4
+ if not klass.class_variables.include? instance
5
+ klass.class_variable_set instance, options[:default]
6
+ end
7
+ end
8
+
9
+ def self.get_from(klass, instance)
10
+ klass.class_variable_get(instance)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Protokoll
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/protokoll.rb CHANGED
@@ -1,38 +1,35 @@
1
1
  require "protokoll/auto_increment"
2
2
  require "protokoll/extract_number"
3
+ require "protokoll/class_variable"
3
4
 
4
5
  module Protokoll
5
6
  extend ActiveSupport::Concern
6
-
7
+
7
8
  module ClassMethods
8
- @@protokoll = nil
9
-
10
- def protokoll
11
- @@protokoll
12
- end
13
-
14
9
  def protokoll(column = nil, _options = {})
15
- @@protokoll = AutoIncrement.new if @@protokoll.nil?
16
- return @@protokoll if column.nil?
10
+ ClassVariable.add_to self, :@@protokoll, :default => AutoIncrement.new
11
+
12
+ prot = ClassVariable.get_from self, :@@protokoll
13
+ return prot if column.nil?
17
14
 
18
15
  options = { :pattern => "%Y%m#####", :number_symbol => "#"}
19
16
  options.merge!(_options)
20
-
21
- @@protokoll.options = options
22
-
17
+
18
+ prot.options = options
19
+
23
20
  before_save do |record|
24
21
  last = record.class.last
25
22
 
26
23
  if last.present?
27
- if @@protokoll.outdated?(last)
28
- @@protokoll.count = 0
24
+ if prot.outdated?(last)
25
+ prot.count = 0
29
26
  else
30
- @@protokoll.count = ExtractNumber.number(last[column], options[:pattern])
27
+ prot.count = ExtractNumber.number(last[column], options[:pattern])
31
28
  end
32
29
  end
33
30
 
34
- @@protokoll.count += 1
35
- record[column] = @@protokoll.next_custom_number(column, @@protokoll.count)
31
+ prot.count += 1
32
+ record[column] = prot.next_custom_number(column, prot.count)
36
33
  end
37
34
  end
38
35
  end
@@ -0,0 +1,3 @@
1
+ class Call < ActiveRecord::Base
2
+ protokoll :number
3
+ end
Binary file
@@ -0,0 +1,8 @@
1
+ class CreateCalls < ActiveRecord::Migration
2
+ def change
3
+ create_table :calls do |t|
4
+ t.string :number
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -11,7 +11,13 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20110923101536) do
14
+ ActiveRecord::Schema.define(:version => 20110928013630) do
15
+
16
+ create_table "calls", :force => true do |t|
17
+ t.string "number"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
15
21
 
16
22
  create_table "principals", :force => true do |t|
17
23
  t.string "protokoll_number"
Binary file
@@ -140,3 +140,58 @@ Migrating to CreatePrincipals (20110923101536)
140
140
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
141
141
   (0.0ms) PRAGMA index_list("principals")
142
142
   (0.0ms) PRAGMA index_list("protocols")
143
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
144
+ Migrating to CreateProtocols (20110923024431)
145
+ Migrating to CreatePrincipals (20110923101536)
146
+ Migrating to CreateCalls (20110928013630)
147
+  (0.0ms) select sqlite_version(*)
148
+  (0.4ms) CREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime) 
149
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110928013630')
150
+  (0.3ms) select sqlite_version(*)
151
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
152
+  (0.0ms) PRAGMA index_list("calls")
153
+  (0.0ms) PRAGMA index_list("principals")
154
+  (0.0ms) PRAGMA index_list("protocols")
155
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
156
+  (0.2ms) select sqlite_version(*)
157
+  (2.9ms) CREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime) 
158
+  (3.5ms) CREATE TABLE "principals" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "protokoll_number" varchar(255), "created_at" datetime, "updated_at" datetime)
159
+  (5.8ms) CREATE TABLE "protocols" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime) 
160
+  (3.9ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
161
+  (0.0ms) PRAGMA index_list("schema_migrations")
162
+  (3.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
163
+  (0.1ms) SELECT version FROM "schema_migrations"
164
+  (4.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20110928013630')
165
+  (6.5ms) INSERT INTO "schema_migrations" (version) VALUES ('20110923024431')
166
+  (5.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20110923101536')
167
+  (0.1ms) select sqlite_version(*)
168
+  (10.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
169
+  (0.1ms) PRAGMA index_list("schema_migrations")
170
+  (6.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
171
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
172
+ Migrating to CreateProtocols (20110923024431)
173
+  (0.4ms) CREATE TABLE "protocols" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime)
174
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110923024431')
175
+ Migrating to CreatePrincipals (20110923101536)
176
+  (0.5ms) CREATE TABLE "principals" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "protokoll_number" varchar(255), "created_at" datetime, "updated_at" datetime)
177
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110923101536')
178
+ Migrating to CreateCalls (20110928013630)
179
+  (0.3ms) CREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime)
180
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110928013630')
181
+  (0.3ms) select sqlite_version(*)
182
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
183
+  (0.0ms) PRAGMA index_list("calls")
184
+  (0.0ms) PRAGMA index_list("principals")
185
+  (0.0ms) PRAGMA index_list("protocols")
186
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
187
+  (0.3ms) select sqlite_version(*)
188
+  (10.5ms) CREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime) 
189
+  (10.8ms) CREATE TABLE "principals" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "protokoll_number" varchar(255), "created_at" datetime, "updated_at" datetime)
190
+  (4.9ms) CREATE TABLE "protocols" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime) 
191
+  (3.9ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
192
+  (0.1ms) PRAGMA index_list("schema_migrations")
193
+  (3.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
194
+  (0.1ms) SELECT version FROM "schema_migrations"
195
+  (9.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20110928013630')
196
+  (15.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20110923024431')
197
+  (12.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20110923101536')