once-ler 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/onceler/recorder.rb +23 -1
  2. metadata +2 -2
@@ -2,10 +2,26 @@ require "onceler/recordable"
2
2
  require "onceler/transactions"
3
3
 
4
4
  module Onceler
5
+ class << self
6
+ def open_transactions
7
+ @open_transactions ||= 0
8
+ end
9
+
10
+ def open_transactions=(val)
11
+ @open_transactions = val
12
+ end
13
+
14
+ attr_accessor :recording
15
+
16
+ def recording?
17
+ @recording
18
+ end
19
+ end
20
+
5
21
  class Recorder
6
22
  include Transactions
7
23
 
8
- attr_accessor :tape, :helper_proxy
24
+ attr_accessor :tape
9
25
 
10
26
  def initialize(group_class)
11
27
  @group_class = group_class
@@ -27,6 +43,7 @@ module Onceler
27
43
  end
28
44
 
29
45
  def record!
46
+ Onceler.recording = true
30
47
  begin_transactions!
31
48
  @tape = @group_class.new
32
49
  @tape.send :extend, Recordable
@@ -43,6 +60,8 @@ module Onceler
43
60
  recording.record_onto!(@tape)
44
61
  end
45
62
  @data = @tape.__data
63
+ ensure
64
+ Onceler.recording = false
46
65
  end
47
66
 
48
67
  def reset!
@@ -80,6 +99,7 @@ module Onceler
80
99
  end
81
100
 
82
101
  def begin_transactions!
102
+ Onceler.open_transactions += 1
83
103
  transaction_classes.each do |klass|
84
104
  begin_transaction(klass.connection)
85
105
  end
@@ -89,6 +109,8 @@ module Onceler
89
109
  transaction_classes.each do |klass|
90
110
  rollback_transaction(klass.connection)
91
111
  end
112
+ ensure
113
+ Onceler.open_transactions -= 1
92
114
  end
93
115
  end
94
116
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: once-ler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-29 00:00:00.000000000 Z
12
+ date: 2014-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord