simple-sql 0.5.27 → 0.5.28

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
  SHA256:
3
- metadata.gz: fd927c6b8b525593892421de3ce43fefa20d036c3d3eaf3ee3f0bbb863108deb
4
- data.tar.gz: 2765ce9e6f3e86801074b014f142a607673f04692c6b0d8d3424c024066f25c9
3
+ metadata.gz: f29429815715916d62f0f03dc831d97e0e0312152f431a49c092a09f1bd48d9e
4
+ data.tar.gz: d02ced1cda31cdca64bbe1f43035cf628d40b80b20c1782bb16e44aee5f15ea8
5
5
  SHA512:
6
- metadata.gz: b4737e323e981525a17129dfdfd1e5a8076e99350ae0f758d6e5d53386ecd57e8d1c66766dbf8ded98b6fdf14ca25ee5a2a616b6c3ae04b844917d71f2ad720a
7
- data.tar.gz: 8a86b32006f6bf1713c71550ea4a32bf4c393558ec8d76738d9905cae114bb470404c5168c10b352b5394b2ea7230277b931089cea9f15110e04522cb279cd5c
6
+ metadata.gz: 1f5c9709450f03cd4b7f8691738f182667b5b53a90fc5e22b4ef00a6c7778bbd7f6f78f153839205e5ecea8a14be9beb84da3d9857e418fc09a7d5f0248881e2
7
+ data.tar.gz: 6ab77cad786ea2f2d2f2b6bea6d49e5b2e76e3bfa5ed15b9d856dd5b8852b2d1c376b841f5c5c78f1b92964dd0c90f87f89247a0879cf8581f5ccd2a647cbdba
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'byebug'
3
+ gem 'pry-byebug'
4
4
  gem 'rubocop', '~> 0.57.2'
5
5
 
6
6
  # Specify your gem's dependencies in {gemname}.gemspec
data/Makefile CHANGED
@@ -1,15 +1,15 @@
1
1
  tests: test4 test5 test6
2
2
 
3
3
  test4:
4
- SIMPLE_SQL_ACTIVERECORD_SPECS="< 5" bundle
4
+ SIMPLE_SQL_ACTIVERECORD_SPECS="> 4,< 5" bundle
5
5
  rspec
6
6
 
7
7
  test5:
8
- SIMPLE_SQL_ACTIVERECORD_SPECS="< 6" bundle
8
+ SIMPLE_SQL_ACTIVERECORD_SPECS="> 5,< 6" bundle update activerecord
9
9
  rspec
10
10
 
11
11
  test6:
12
- SIMPLE_SQL_ACTIVERECORD_SPECS="< 7" bundle
12
+ SIMPLE_SQL_ACTIVERECORD_SPECS="> 6,< 7" bundle update activerecord
13
13
  rspec
14
14
 
15
15
  stats:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.27
1
+ 0.5.28
data/lib/simple/sql.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "sql/config"
12
12
  require_relative "sql/logging"
13
13
  require_relative "sql/connection"
14
14
  require_relative "sql/table_print"
15
+ require_relative "sql/monkey_patches"
15
16
 
16
17
  module Simple
17
18
  # The Simple::SQL module
@@ -1,152 +1,8 @@
1
1
  module Simple
2
2
  module SQL
3
3
  module Helpers
4
+ # for backwards compatibility
5
+ Immutable = ::Simple::Immutable
4
6
  end
5
7
  end
6
8
  end
7
-
8
- class Simple::SQL::Helpers::Immutable
9
- SELF = self
10
-
11
- # turns an object, which can be a hash or array of hashes, arrays, and scalars
12
- # into an object which you can use to access with dot methods.
13
- def self.create(object, max_depth = 5)
14
- case object
15
- when Array
16
- raise ArgumentError, "Object nested too deep (or inner loop?)" if max_depth < 0
17
-
18
- object.map { |obj| create obj, max_depth - 1 }
19
- when Hash
20
- new(object)
21
- else
22
- object
23
- end
24
- end
25
-
26
- private
27
-
28
- def initialize(hsh)
29
- @hsh = hsh
30
- end
31
-
32
- def method_missing(sym, *args, &block)
33
- if args.empty? && !block
34
- begin
35
- value = @hsh.fetch(sym.to_sym) { @hsh.fetch(sym.to_s) }
36
- return SELF.create(value)
37
- rescue KeyError
38
- # STDERR.puts "Missing attribute #{sym} for Immutable w/#{@hsh.inspect}"
39
- nil
40
- end
41
- end
42
-
43
- super
44
- end
45
-
46
- public
47
-
48
- def respond_to_missing?(method_name, include_private = false)
49
- @hsh.key?(method_name.to_sym) ||
50
- @hsh.key?(method_name.to_s) ||
51
- super
52
- end
53
-
54
- def inspect
55
- "<Immutable: #{@hsh.inspect}>"
56
- end
57
-
58
- def respond_to?(sym)
59
- super || @hsh.key?(sym.to_s) || @hsh.key?(sym.to_sym)
60
- end
61
-
62
- def ==(other)
63
- @hsh == other
64
- end
65
- end
66
-
67
- if $PROGRAM_NAME == __FILE__
68
-
69
- # rubocop:disable Metrics/AbcSize
70
-
71
- require "test-unit"
72
-
73
- class Simple::SQL::Helpers::Immutable::TestCase < Test::Unit::TestCase
74
- Immutable = ::Simple::SQL::Helpers::Immutable
75
-
76
- def hsh
77
- {
78
- a: "a-value",
79
- "b": "b-value",
80
- "child": {
81
- name: "childname",
82
- grandchild: {
83
- name: "grandchildname"
84
- }
85
- },
86
- "children": [
87
- "anna",
88
- "arthur",
89
- {
90
- action: {
91
- keep_your_mouth_shut: true
92
- }
93
- }
94
- ]
95
- }
96
- end
97
-
98
- def immutable
99
- Immutable.create hsh
100
- end
101
-
102
- def test_hash_access
103
- assert_equal "a-value", immutable.a
104
- assert_equal "b-value", immutable.b
105
- end
106
-
107
- def test_comparison
108
- immutable = Immutable.create hsh
109
-
110
- assert_equal immutable, hsh
111
- assert_not_equal({}, immutable)
112
- end
113
-
114
- def test_child_access
115
- child = immutable.child
116
- assert_kind_of(Immutable, child)
117
- assert_equal "childname", immutable.child.name
118
- assert_equal "grandchildname", immutable.child.grandchild.name
119
- end
120
-
121
- def test_array_access
122
- assert_kind_of(Array, immutable.children)
123
- assert_equal 3, immutable.children.length
124
- assert_equal "anna", immutable.children[0]
125
-
126
- assert_kind_of(Immutable, immutable.children[2])
127
- assert_equal true, immutable.children[2].action.keep_your_mouth_shut
128
- end
129
-
130
- def test_base_class
131
- assert_nothing_raised do
132
- immutable.object_id
133
- end
134
- end
135
-
136
- def test_missing_keys
137
- assert_raise(NoMethodError) do
138
- immutable.foo
139
- end
140
- end
141
-
142
- def test_skip_when_args_or_block
143
- assert_raise(NoMethodError) do
144
- immutable.a(1, 2, 3)
145
- end
146
- assert_raise(NoMethodError) do
147
- immutable.a { :dummy }
148
- end
149
- end
150
- end
151
-
152
- end
@@ -1,4 +1,5 @@
1
1
  require_relative "./immutable"
2
+ require "simple/immutable"
2
3
 
3
4
  module Simple::SQL::Helpers::RowConverter
4
5
  SELF = self
@@ -57,7 +58,7 @@ module Simple::SQL::Helpers::RowConverter
57
58
  end
58
59
 
59
60
  class ImmutableConverter < TypeConverter #:nodoc:
60
- Immutable = ::Simple::SQL::Helpers::Immutable
61
+ Immutable = ::Simple::Immutable
61
62
 
62
63
  def build_row_in_target_type(hsh)
63
64
  Immutable.create hsh
@@ -0,0 +1,56 @@
1
+ # This file contains some monkey patches
2
+
3
+ module Simple::SQL::MonkeyPatches
4
+ def self.warn(msg)
5
+ @@warned ||= {}
6
+ return if @@warned[msg]
7
+
8
+ @@warned[msg] = true
9
+
10
+ msg = <<~MSG
11
+ == patching notice: ======================================================================================
12
+ Note that simple-sql changes the behaviour of underlying gems in subtle ways:
13
+ #{msg}
14
+ ==========================================================================================================
15
+ MSG
16
+
17
+ STDERR.puts msg
18
+ end
19
+ end
20
+
21
+ case ActiveRecord.gem_version.to_s
22
+ when /^4/
23
+ :nop
24
+ when /^5.2/
25
+ unless defined?(ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper)
26
+ raise "Make sure to properly require active-record first"
27
+ end
28
+
29
+ # Rails5 introduced a Reaper which starts a Thread which checks for unused connections. However,
30
+ # these threads are never cleaned up. This monkey patch disables the creation of those threads
31
+ # in the first place, consequently preventing leakage of threads.
32
+ #
33
+ # see see https://github.com/rails/rails/issues/33600 and related commits and issues.
34
+ class ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper
35
+ def run
36
+ return unless frequency && frequency > 0
37
+ Simple::SQL::MonkeyPatches.warn "disable Reaper for all ActiveRecord connection pools, see https://github.com/rails/rails/issues/33600"
38
+ end
39
+ end
40
+
41
+ when /^6/
42
+ unless defined?(ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper)
43
+ raise "Make sure to properly require active-record first"
44
+ end
45
+
46
+ # Rails6 fixes the issue w/reapers leaking threads; by properly cleaning up these threads
47
+ # (or so one hopes after looking at connection_pool.rb). However, in the interest of simple-sql
48
+ # being more or less ActiveRecord agnostic we disable reaping here as well. (Also, that code
49
+ # looks pretty complex to me).
50
+ class ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper
51
+ def run
52
+ return unless frequency && frequency > 0
53
+ Simple::SQL::MonkeyPatches.warn "disable Reaper for all ActiveRecord connection pools, see https://github.com/rails/rails/issues/33600"
54
+ end
55
+ end
56
+ end
data/simple-sql.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |gem|
28
28
  gem.add_dependency 'expectation', '~> 1'
29
29
 
30
30
  gem.add_dependency 'digest-crc', '~> 0'
31
+ gem.add_dependency 'simple-immutable', '~> 1.0'
31
32
 
32
33
  # during tests we check the SIMPLE_SQL_ACTIVERECORD_SPECS environment setting.
33
34
  # Run make tests to run all tests
@@ -61,7 +61,7 @@ describe "Simple::SQL.each" do
61
61
 
62
62
  expect(received.first.id).to eq(1)
63
63
  expect(received[1].dupe).to eq(2)
64
- expect(received.map(&:class).uniq).to eq([Simple::SQL::Helpers::Immutable])
64
+ expect(received.map(&:class).uniq).to eq([Simple::Immutable])
65
65
  end
66
66
  end
67
67
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,7 @@ end
6
6
  ENV["RACK_ENV"] = "test"
7
7
  ENV["RAILS_ENV"] = "test"
8
8
 
9
- require "byebug"
9
+ require "pry-byebug"
10
10
  require "rspec"
11
11
 
12
12
  Dir.glob("./spec/support/**/*.rb").sort.each { |path| load path }
@@ -1,5 +1,9 @@
1
1
  # connect to the database and setup the schema
2
2
  require "active_record"
3
+
4
+ # it is important to require simple-sql here to activate monkey patches
5
+ require "simple-sql"
6
+
3
7
  require "yaml"
4
8
  abc = YAML.load_file("config/database.yml")
5
9
  ActiveRecord::Base.establish_connection(abc["test"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.27
4
+ version: 0.5.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-22 00:00:00.000000000 Z
12
+ date: 2020-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser
@@ -73,6 +73,20 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: simple-immutable
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
76
90
  - !ruby/object:Gem::Dependency
77
91
  name: activerecord
78
92
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +226,7 @@ files:
212
226
  - lib/simple/sql/helpers/immutable.rb
213
227
  - lib/simple/sql/helpers/row_converter.rb
214
228
  - lib/simple/sql/logging.rb
229
+ - lib/simple/sql/monkey_patches.rb
215
230
  - lib/simple/sql/result.rb
216
231
  - lib/simple/sql/result/association_loader.rb
217
232
  - lib/simple/sql/result/records.rb