fresh_connection 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f896f7889dfe9faf024a5905f135bee636f35fe0
4
- data.tar.gz: bf059b853f63b8beb128708c5c6f3363ca2393ca
3
+ metadata.gz: 3e470a4665ec85ef6b012e95e365c5038d996aa6
4
+ data.tar.gz: a764c721578fbdc080d2351333dbd34716be123a
5
5
  SHA512:
6
- metadata.gz: 9e7f30d3bcbf4e26c6ba5eb4222f3e59ee27237f2d32b7a04948f5bdbb325f9c72c43f74af43916c515fc56fa57d7b93d355b03e15771fc9a24ae301bf08e109
7
- data.tar.gz: bfc44fd46e95eb800008fb30917b3195f978b0ea6ebdfbe24b9b65fd13f09335c298254c0661797339bbe7894f62cfd8224fc019099ea51af36bd0ff57adcb4d
6
+ metadata.gz: 98a9036418869064befea2b8d7f9e539a30bc11a74ab3b3039057f9a00224339855612de0586bdd7cb1aeef451c09fa65ecb51c6378182a6b43151d3788aed9f
7
+ data.tar.gz: 4456c9b0d2798facd1b8b3c83a55f7d61b52c8708ce899266ac4307b1034290474639dde84909099be02c42d253fce5bbfcf07f2182115f5d51aa13e4ddb67a3
@@ -16,10 +16,6 @@ module FreshConnection
16
16
  @klass.manage_access(slave_access) { super }
17
17
  end
18
18
 
19
- def pluck(*args)
20
- @klass.manage_access(enable_slave_access) { super }
21
- end
22
-
23
19
  private
24
20
 
25
21
  def exec_queries_with_fresh_connection
@@ -31,14 +27,36 @@ module FreshConnection
31
27
  end
32
28
 
33
29
  module ForRails4
30
+ def pluck(*args)
31
+ @klass.manage_access(enable_slave_access) { super }
32
+ end
33
+
34
34
  private
35
+
35
36
  def enable_slave_access
36
37
  connection.open_transactions == 0 && (readonly_value.nil? || readonly_value)
37
38
  end
38
39
  end
39
40
 
40
41
  module ForRails3
42
+ def pluck(column_name)
43
+ if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s)
44
+ column_name = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
45
+ end
46
+
47
+ result = @klass.manage_access(enable_slave_access) do
48
+ klass.connection.select_all(select(column_name).arel, nil)
49
+ end
50
+
51
+ last_columns = result.last.keys.last
52
+
53
+ result.map do |attributes|
54
+ klass.type_cast_attribute(last_columns, klass.initialize_attributes(attributes))
55
+ end
56
+ end
57
+
41
58
  private
59
+
42
60
  def enable_slave_access
43
61
  connection.open_transactions == 0 && (@readonly_value.nil? || @readonly_value)
44
62
  end
@@ -4,16 +4,15 @@ module FreshConnection
4
4
  def self.included(base)
5
5
  base.__send__(:attr_writer, :model_class)
6
6
  base.alias_method_chain :configure_connection, :fresh_connection
7
- base.alias_method_chain :execute, :fresh_connection
8
7
  end
9
8
 
10
- def execute_with_fresh_connection(sql, name = nil)
11
- if @model_class && FreshConnection::AccessControl.slave_access?
9
+ def select_all(arel, name = nil, binds = [])
10
+ if FreshConnection::AccessControl.slave_access?
12
11
  change_connection do
13
- execute_without_fresh_connection(sql, "[#{@model_class.slave_group}] #{name}")
12
+ super(arel, "[#{@model_class.slave_group}] #{name}", binds)
14
13
  end
15
14
  else
16
- execute_without_fresh_connection(sql, name)
15
+ super
17
16
  end
18
17
  end
19
18
 
@@ -1,4 +1,4 @@
1
1
  module FreshConnection
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fresh_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsukasa OISHI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-02 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord