protokoll 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/protokoll/class_variable.rb +13 -0
- data/lib/protokoll/version.rb +1 -1
- data/lib/protokoll.rb +14 -17
- data/test/dummy/app/models/call.rb +3 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20110928013630_create_calls.rb +8 -0
- data/test/dummy/db/schema.rb +7 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +55 -0
- data/test/dummy/log/test.log +36119 -0
- data/test/protokoll_test.rb +10 -0
- metadata +10 -13
- data/test/dummy/test/fixtures/principals.yml +0 -7
- data/test/dummy/test/fixtures/protocols.yml +0 -7
- data/test/dummy/test/unit/principal_test.rb +0 -7
- data/test/dummy/test/unit/protocol_test.rb +0 -7
@@ -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
|
data/lib/protokoll/version.rb
CHANGED
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
|
-
|
16
|
-
|
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
|
-
|
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
|
28
|
-
|
24
|
+
if prot.outdated?(last)
|
25
|
+
prot.count = 0
|
29
26
|
else
|
30
|
-
|
27
|
+
prot.count = ExtractNumber.number(last[column], options[:pattern])
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
34
|
-
|
35
|
-
record[column] =
|
31
|
+
prot.count += 1
|
32
|
+
record[column] = prot.next_custom_number(column, prot.count)
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -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 =>
|
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"
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -140,3 +140,58 @@ Migrating to CreatePrincipals (20110923101536)
|
|
140
140
|
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
141
141
|
[1m[35m (0.0ms)[0m PRAGMA index_list("principals")
|
142
142
|
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("protocols")[0m
|
143
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
144
|
+
Migrating to CreateProtocols (20110923024431)
|
145
|
+
Migrating to CreatePrincipals (20110923101536)
|
146
|
+
Migrating to CreateCalls (20110928013630)
|
147
|
+
[1m[35m (0.0ms)[0m select sqlite_version(*)
|
148
|
+
[1m[36m (0.4ms)[0m [1mCREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime) [0m
|
149
|
+
[1m[35m (0.1ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ('20110928013630')
|
150
|
+
[1m[36m (0.3ms)[0m [1mselect sqlite_version(*)[0m
|
151
|
+
[1m[35m (0.1ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|
152
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("calls")[0m
|
153
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("principals")
|
154
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("protocols")[0m
|
155
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
156
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
157
|
+
[1m[36m (2.9ms)[0m [1mCREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime) [0m
|
158
|
+
[1m[35m (3.5ms)[0m CREATE TABLE "principals" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "protokoll_number" varchar(255), "created_at" datetime, "updated_at" datetime)
|
159
|
+
[1m[36m (5.8ms)[0m [1mCREATE TABLE "protocols" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime) [0m
|
160
|
+
[1m[35m (3.9ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
161
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
162
|
+
[1m[35m (3.7ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
163
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
164
|
+
[1m[35m (4.4ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20110928013630')
|
165
|
+
[1m[36m (6.5ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20110923024431')[0m
|
166
|
+
[1m[35m (5.2ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20110923101536')
|
167
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
168
|
+
[1m[35m (10.5ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
169
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
170
|
+
[1m[35m (6.8ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
171
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
172
|
+
Migrating to CreateProtocols (20110923024431)
|
173
|
+
[1m[35m (0.4ms)[0m CREATE TABLE "protocols" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime)
|
174
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20110923024431')[0m
|
175
|
+
Migrating to CreatePrincipals (20110923101536)
|
176
|
+
[1m[35m (0.5ms)[0m CREATE TABLE "principals" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "protokoll_number" varchar(255), "created_at" datetime, "updated_at" datetime)
|
177
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20110923101536')[0m
|
178
|
+
Migrating to CreateCalls (20110928013630)
|
179
|
+
[1m[35m (0.3ms)[0m CREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime)
|
180
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20110928013630')[0m
|
181
|
+
[1m[35m (0.3ms)[0m select sqlite_version(*)
|
182
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
183
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("calls")
|
184
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("principals")[0m
|
185
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("protocols")
|
186
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
187
|
+
[1m[35m (0.3ms)[0m select sqlite_version(*)
|
188
|
+
[1m[36m (10.5ms)[0m [1mCREATE TABLE "calls" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime) [0m
|
189
|
+
[1m[35m (10.8ms)[0m CREATE TABLE "principals" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "protokoll_number" varchar(255), "created_at" datetime, "updated_at" datetime)
|
190
|
+
[1m[36m (4.9ms)[0m [1mCREATE TABLE "protocols" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime) [0m
|
191
|
+
[1m[35m (3.9ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
192
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
193
|
+
[1m[35m (3.7ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
194
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
195
|
+
[1m[35m (9.8ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20110928013630')
|
196
|
+
[1m[36m (15.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20110923024431')[0m
|
197
|
+
[1m[35m (12.0ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20110923101536')
|