fixjour 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fixjour/builders.rb +1 -0
- data/lib/fixjour/counter.rb +20 -0
- data/lib/fixjour/verify.rb +7 -7
- data/lib/fixjour.rb +1 -0
- metadata +2 -1
data/lib/fixjour/builders.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Fixjour
|
2
|
+
module Counter
|
3
|
+
def self.reset(key=nil)
|
4
|
+
if key
|
5
|
+
@counters[key] = lambda { s ||= 0; s += 1 }
|
6
|
+
else
|
7
|
+
@counters = Hash.new { |h,k| s ||= 0; c = lambda { s += 1 }; h[k] = c }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
reset
|
11
|
+
|
12
|
+
def self.counter(key)
|
13
|
+
@counters[key][]
|
14
|
+
end
|
15
|
+
|
16
|
+
def counter(key=nil)
|
17
|
+
Counter.counter(key)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/fixjour/verify.rb
CHANGED
@@ -8,19 +8,19 @@ module Fixjour
|
|
8
8
|
def verify!
|
9
9
|
builders.each do |klass|
|
10
10
|
result = new_record(klass)
|
11
|
-
|
11
|
+
|
12
12
|
unless result.valid?
|
13
13
|
error(klass, InvalidBuilder, "returns an invalid object: #{result.errors.inspect}")
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
unless result.new_record?
|
17
17
|
error(klass, BuilderSavedRecord, "must return a new record")
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
unless result.is_a?(klass)
|
21
21
|
error(klass, WrongBuilderType, "must return an instance of #{klass}")
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
klass.transaction do
|
25
25
|
begin
|
26
26
|
result.save!
|
@@ -40,13 +40,13 @@ module Fixjour
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def new_record(klass)
|
45
45
|
evaluator.send("new_#{name_for(klass)}")
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
private
|
49
|
-
|
49
|
+
|
50
50
|
def error(klass, exception, msg)
|
51
51
|
raise exception.new("The builder for #{klass} #{msg} ")
|
52
52
|
end
|
data/lib/fixjour.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixjour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Nakajima
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/core_ext/object.rb
|
37
37
|
- lib/fixjour
|
38
38
|
- lib/fixjour/builders.rb
|
39
|
+
- lib/fixjour/counter.rb
|
39
40
|
- lib/fixjour/definitions.rb
|
40
41
|
- lib/fixjour/deprecation.rb
|
41
42
|
- lib/fixjour/errors.rb
|