Skip to content

Commit 8e859ce

Browse files
committed
Merge branch 'master' of github.com:ged/ruby-pg
2 parents 68ac787 + 0ea7a94 commit 8e859ce

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

lib/pg/basic_type_map_for_queries.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def get_array_type(value)
182182
Array => :get_array_type,
183183
BinaryData => [1, 'bytea'],
184184
})
185+
private_constant :DEFAULT_TYPE_MAP
185186

186187
DEFAULT_ARRAY_TYPE_MAP = PG.make_shareable({
187188
TrueClass => [0, '_bool'],
@@ -193,5 +194,5 @@ def get_array_type(value)
193194
Time => [0, '_timestamptz'],
194195
IPAddr => [0, '_inet'],
195196
})
196-
197+
private_constant :DEFAULT_ARRAY_TYPE_MAP
197198
end

lib/pg/basic_type_registry.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CoderMap
4040
bool
4141
date timestamp timestamptz
4242
].inject({}){|h,e| h[e] = true; h }.freeze
43+
private_constant :DONT_QUOTE_TYPES
4344

4445
def initialize(result, coders_by_name, format, arraycoder)
4546
coder_map = {}
@@ -150,6 +151,7 @@ def map_for(format, direction)
150151
module Checker
151152
ValidFormats = { 0 => true, 1 => true }.freeze
152153
ValidDirections = { :encoder => true, :decoder => true }.freeze
154+
private_constant :ValidFormats, :ValidDirections
153155

154156
protected def check_format_and_direction(format, direction)
155157
raise(ArgumentError, "Invalid format value %p" % format) unless ValidFormats[format]
@@ -292,6 +294,6 @@ def register_default_types
292294

293295
alias define_default_types register_default_types
294296

295-
# @private
296297
DEFAULT_TYPE_REGISTRY = PG.make_shareable(PG::BasicTypeRegistry.new.register_default_types)
298+
private_constant :DEFAULT_TYPE_REGISTRY
297299
end

lib/pg/connection.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PG::Connection
3131

3232
# The order the options are passed to the ::connect method.
3333
CONNECT_ARGUMENT_ORDER = %w[host port options tty dbname user password].freeze
34-
34+
private_constant :CONNECT_ARGUMENT_ORDER
3535

3636
### Quote a single +value+ for use in a connection-parameter string.
3737
def self.quote_connstr( value )
@@ -47,6 +47,7 @@ def self.connect_hash_to_string( hash )
4747

4848
# Shareable program name for Ractor
4949
PROGRAM_NAME = $PROGRAM_NAME.dup.freeze
50+
private_constant :PROGRAM_NAME
5051

5152
# Parse the connection +args+ into a connection-parameter string.
5253
# See PG::Connection.new for valid arguments.
@@ -117,6 +118,7 @@ def inspect
117118
end
118119

119120
BinarySignature = "PGCOPY\n\377\r\n\0".b
121+
private_constant :BinarySignature
120122

121123
# call-seq:
122124
# conn.copy_data( sql [, coder] ) {|sql_result| ... } -> PG::Result
@@ -851,6 +853,7 @@ def ping(*args)
851853
:setdblogin => [:async_connect, :sync_connect],
852854
:ping => [:async_ping, :sync_ping],
853855
})
856+
private_constant :REDIRECT_CLASS_METHODS
854857

855858
# These methods are affected by PQsetnonblocking
856859
REDIRECT_SEND_METHODS = PG.make_shareable({
@@ -860,6 +863,7 @@ def ping(*args)
860863
:put_copy_end => [:async_put_copy_end, :sync_put_copy_end],
861864
:flush => [:async_flush, :sync_flush],
862865
})
866+
private_constant :REDIRECT_SEND_METHODS
863867
REDIRECT_METHODS = {
864868
:exec => [:async_exec, :sync_exec],
865869
:query => [:async_exec, :sync_exec],
@@ -877,6 +881,7 @@ def ping(*args)
877881
:client_encoding= => [:async_set_client_encoding, :sync_set_client_encoding],
878882
:cancel => [:async_cancel, :sync_cancel],
879883
}
884+
private_constant :REDIRECT_METHODS
880885

881886
if PG::Connection.instance_methods.include? :async_encrypt_password
882887
REDIRECT_METHODS.merge!({

spec/pg/connection_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,17 @@
287287
end
288288

289289
it "sets a shortened fallback_application_name on new connections" do
290-
old_script_name = PG::Connection::PROGRAM_NAME
290+
old_script_name = PG::Connection.class_eval("PROGRAM_NAME")
291291
begin
292-
PG::Connection.const_set(:PROGRAM_NAME, "/this/is/a/very/long/path/with/many/directories/to/our/beloved/ruby")
292+
prg = '/this/is/a/very/long/path/with/many/directories/to/our/beloved/ruby'
293+
PG::Connection.class_eval("PROGRAM_NAME=#{prg.inspect}")
293294
conn_string = PG::Connection.parse_connect_args( 'dbname=test' )
294295
conn_name = conn_string[ /application_name='(.*?)'/, 1 ]
295-
expect( conn_name ).to include( PG::Connection::PROGRAM_NAME[0..10] )
296-
expect( conn_name ).to include( PG::Connection::PROGRAM_NAME[-10..-1] )
296+
expect( conn_name ).to include( prg[0..10] )
297+
expect( conn_name ).to include( prg[-10..-1] )
297298
expect( conn_name.length ).to be <= 64
298299
ensure
299-
PG::Connection.const_set(:PROGRAM_NAME, old_script_name)
300+
PG::Connection.class_eval("PROGRAM_NAME=PG.make_shareable(#{old_script_name.inspect})")
300301
end
301302
end
302303
end

0 commit comments

Comments
 (0)