pg-ephemeral 0.0.1-arm64-darwin

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.
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+ require 'pathname'
5
+ require 'json'
6
+ require 'pg'
7
+ require 'rubygems'
8
+
9
+ module PgEphemeral
10
+ def self.binary_path
11
+ gem_dir = Gem::Specification.find_by_name('pg-ephemeral').gem_dir
12
+ File.join(gem_dir, 'bin', 'pg-ephemeral')
13
+ end
14
+
15
+ def self.version
16
+ stdout, _stderr, status = Open3.capture3(binary_path, '--version')
17
+
18
+ unless status.success?
19
+ raise "Failed to get version from pg-ephemeral binary"
20
+ end
21
+
22
+ match = stdout.match(/\Apg-ephemeral (?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(-(?<pre>.+))?\n\z/)
23
+
24
+ raise "Failed to parse version from pg-ephemeral binary" unless match
25
+
26
+ version = "#{match[:major]}.#{match[:minor]}.#{match[:patch]}"
27
+ version += ".#{match[:pre]}" if match[:pre]
28
+ version
29
+ end
30
+
31
+ def self.platform_supported?
32
+ _stdout, status = Open3.capture2(binary_path, 'platform', 'support')
33
+ status.success?
34
+ end
35
+
36
+ def self.with_server(instance_name: 'main', config: nil, &block)
37
+ run_server(instance_name, config, &block)
38
+ end
39
+
40
+ def self.with_connection(instance_name: 'main', config: nil, &block)
41
+ with_server(instance_name: instance_name, config: config) do |server|
42
+ connection = PG.connect(server.url)
43
+
44
+ begin
45
+ block.call(connection)
46
+ ensure
47
+ connection.close
48
+ end
49
+ end
50
+ end
51
+
52
+ def self.run_server(instance_name, config, &block)
53
+ command = [binary_path]
54
+
55
+ if config
56
+ command.concat(['--config-file', config])
57
+ end
58
+
59
+ command.concat([
60
+ 'integration-server',
61
+ '--instance', instance_name,
62
+ '--protocol', 'v0'
63
+ ])
64
+
65
+ Open3.popen2(*command) do |stdin, stdout, wait_thread|
66
+ config_json = stdout.gets
67
+
68
+ raise 'Failed to read server configuration' unless config_json
69
+
70
+ url = JSON.parse(config_json).fetch('url')
71
+ server = Server.new(url, stdin, wait_thread)
72
+
73
+ begin
74
+ block.call(server)
75
+ ensure
76
+ server.shutdown
77
+ end
78
+ end
79
+ end
80
+ private_class_method :run_server
81
+
82
+ class Server
83
+ attr_reader :url
84
+
85
+ def initialize(url, stdin, wait_thread)
86
+ @url = url
87
+ @stdin = stdin
88
+ @wait_thread = wait_thread
89
+ end
90
+
91
+ def shutdown
92
+ @stdin.close unless @stdin.closed?
93
+ @wait_thread.value
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pg-ephemeral
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: arm64-darwin
6
+ authors:
7
+ - Markus Schirp
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: pg
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.5'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.5'
26
+ description: Provides ephemeral PostgreSQL instances for testing, wrapping the pg-ephemeral
27
+ project binary
28
+ email:
29
+ - mbj@schirp-dso.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE.txt
35
+ - bin/pg-ephemeral
36
+ - bin/pg-ephemeral.dSYM/Contents/Info.plist
37
+ - bin/pg-ephemeral.dSYM/Contents/Resources/DWARF/pg_ephemeral-5f2555087ab7ce37
38
+ - bin/pg-ephemeral.dSYM/Contents/Resources/Relocations/aarch64/pg_ephemeral-5f2555087ab7ce37.yml
39
+ - lib/pg_ephemeral.rb
40
+ homepage: https://github.com/mbj/mrs/tree/main/pg-ephemeral
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ homepage_uri: https://github.com/mbj/mrs/tree/main/pg-ephemeral
45
+ source_code_uri: https://github.com/mbj/mrs
46
+ changelog_uri: https://github.com/mbj/mrs/blob/main/pg-ephemeral/CHANGELOG.md
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.6.9
62
+ specification_version: 4
63
+ summary: Ruby wrapper for pg-ephemeral PostgreSQL testing utility
64
+ test_files: []