active_record-sequence 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2043cdec6848e80f36c99347db78eb9d68f879a2
4
- data.tar.gz: cd9abcd82560fb81592fd8542c30760e89f450fa
3
+ metadata.gz: a5f0d7c7abbc69c87cf51109c788c28edb31b08d
4
+ data.tar.gz: 4c2025194325a6b489811fcfb6c4e012c271b4cb
5
5
  SHA512:
6
- metadata.gz: 78c26a534695256415675748ba9fa6d2c6b9b2ca617146f226e1d5e447f5940bfb3c45614ba9bebfc0d9ee4e21104a16e9376498529e96fe21483364315d3b84
7
- data.tar.gz: 7057f3e410367eefded9028303b65993887cc78b1df61d154e0adbd14f920df3e4a3d16c30e70e72882ee6da022a295cf052642c98646c073c819408720a2439
6
+ metadata.gz: 5d54e541caf29319fa0d3424474f2905127935bb2888e85f0bf06853a9991e080f342b6a13a3436342bf5bf018bd308f931836d192e5e3e340913eea783d33bb
7
+ data.tar.gz: c715186042c3d1e78f5d0adde3e2573fe5086c5f07b092eba82034ca81b59d12b41b446c1af0c84cd2c2c69d12a8d6fe4aa84a0632f50ab84758349c9767f1b6
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://travis-ci.org/bolshakov/active_record-sequence.svg?branch=master)](https://travis-ci.org/bolshakov/active_record-sequence)
2
+ [![Gem Version](https://badge.fury.io/rb/active_record-sequence.svg)](https://badge.fury.io/rb/active_record-sequence)
2
3
 
3
4
  # ActiveRecord::Sequence
4
5
 
@@ -36,7 +36,9 @@ module ActiveRecord
36
36
  def create(name, options = {})
37
37
  create_sql = SequenceSQLBuilder.new(name, options).to_sql
38
38
  handle_postgres_errors(CREATE_ERRORS) do
39
- connection.execute(create_sql)
39
+ with_connection do |connection|
40
+ connection.execute(create_sql)
41
+ end
40
42
  end
41
43
  new(name)
42
44
  end
@@ -50,12 +52,17 @@ module ActiveRecord
50
52
  def drop(name)
51
53
  drop_sql = format('DROP SEQUENCE %s', name)
52
54
  handle_postgres_errors(DROP_ERRORS) do
53
- connection.execute(drop_sql)
55
+ with_connection do |connection|
56
+ connection.execute(drop_sql)
57
+ end
54
58
  end
55
59
  end
56
60
 
57
- def connection
58
- @connection ||= ActiveRecord::Base.retrieve_connection
61
+ # @api private
62
+ def with_connection
63
+ ActiveRecord::Base.connection_pool.with_connection do |connection|
64
+ yield(connection)
65
+ end
59
66
  end
60
67
 
61
68
  # @param mappings [{}] from PG errors to library errors
@@ -73,7 +80,6 @@ module ActiveRecord
73
80
  # @param name [String]
74
81
  def initialize(name)
75
82
  @name = name
76
- @connection = self.class.connection
77
83
  end
78
84
 
79
85
  NEXT_ERRORS = {
@@ -104,14 +110,22 @@ module ActiveRecord
104
110
 
105
111
  private
106
112
 
107
- attr_reader :connection
108
113
  delegate :handle_postgres_errors, to: :class
114
+ delegate :with_connection, to: :class
109
115
 
110
116
  def execute(sql, *args)
111
- quoted_args = args.map { |arg| connection.quote(arg) }
112
- formatted_sql = format(sql, *quoted_args)
117
+ with_connection do |connection|
118
+ connection.select_value(prepare_query(sql, *args)).to_i
119
+ end
120
+ end
113
121
 
114
- connection.select_value(formatted_sql).to_i
122
+ def prepare_query(sql, *args)
123
+ quoted_args = args.map do |arg|
124
+ with_connection do |connection|
125
+ connection.quote(arg)
126
+ end
127
+ end
128
+ format(sql, *quoted_args)
115
129
  end
116
130
  end
117
131
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class Sequence
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-sequence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tema Bolshakov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-25 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord