returning 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/lib/returning/active_record/adapter.rb +24 -15
- data/lib/returning/version.rb +1 -1
- data/lib/returning.rb +3 -2
- data/spec/returning_spec.rb +12 -0
- data/spec/support/ar.rb +5 -0
- metadata +4 -3
data/CHANGELOG.md
ADDED
@@ -13,27 +13,36 @@ module Returning
|
|
13
13
|
!!@_returning
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
records
|
21
|
-
else
|
22
|
-
super
|
23
|
-
end
|
16
|
+
def exec_with_returning(sql, binds)
|
17
|
+
records = @_returning[1].find_by_sql("#{to_sql(sql)} RETURNING #{@_returning[0]}", binds)
|
18
|
+
records.each { |r| r.readonly! }
|
19
|
+
records
|
24
20
|
end
|
25
21
|
|
26
|
-
|
27
|
-
if
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
[:update, :delete].each do |method|
|
23
|
+
if ::ActiveRecord::VERSION::STRING =~ /^3\.0/
|
24
|
+
class_eval <<-RUBY, __FILE__, __LINE__+1
|
25
|
+
def #{method}(sql, name = nil)
|
26
|
+
if @_returning
|
27
|
+
exec_with_returning(sql, [])
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
RUBY
|
31
33
|
else
|
32
|
-
|
34
|
+
class_eval <<-RUBY, __FILE__, __LINE__+1
|
35
|
+
def #{method}(sql, name = nil, binds = [])
|
36
|
+
if @_returning
|
37
|
+
exec_with_returning(sql, binds)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
RUBY
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
36
|
-
|
37
46
|
def returning(columns, klass)
|
38
47
|
old_returning, @_returning = @_returning, [columns, klass]
|
39
48
|
yield
|
data/lib/returning/version.rb
CHANGED
data/lib/returning.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
3
|
+
|
1
4
|
require "returning/version"
|
2
5
|
require 'returning/active_record/returning'
|
3
6
|
require 'returning/active_record/adapter'
|
4
7
|
|
5
|
-
require 'active_record'
|
6
|
-
require 'active_record/connection_adapters/postgresql_adapter'
|
7
8
|
|
8
9
|
module Returning
|
9
10
|
# Your code goes here...
|
data/spec/returning_spec.rb
CHANGED
@@ -22,6 +22,12 @@ describe Returning do
|
|
22
22
|
post.save(:returning => 'name').should eql(post)
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
context 'with query cache' do
|
27
|
+
it 'works' do
|
28
|
+
PostQueryCache.first.update_attributes :name => 'cached'
|
29
|
+
end
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
describe '#destroy' do
|
@@ -30,5 +36,11 @@ describe Returning do
|
|
30
36
|
post.name = 'hello world'
|
31
37
|
post.destroy(:returning => 'name').name.should == 'hello world'
|
32
38
|
end
|
39
|
+
|
40
|
+
context 'with query cache' do
|
41
|
+
it 'works' do
|
42
|
+
expect { PostQueryCache.first.destroy }.not_to raise_error
|
43
|
+
end
|
44
|
+
end
|
33
45
|
end
|
34
46
|
end
|
data/spec/support/ar.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: returning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eugene Pimenov
|
@@ -58,6 +58,7 @@ extra_rdoc_files: []
|
|
58
58
|
|
59
59
|
files:
|
60
60
|
- .gitignore
|
61
|
+
- CHANGELOG.md
|
61
62
|
- Gemfile
|
62
63
|
- Gemfile3.1
|
63
64
|
- README.md
|