bindan 0.1.0

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
+ require_relative "../error"
2
+ require "uri"
3
+ begin
4
+ require "google/cloud/storage"
5
+ rescue LoadError => e
6
+ warn e
7
+ module Google
8
+ module Cloud
9
+ class Storage
10
+ def initialize(**kwargs)
11
+ end
12
+
13
+ def bucket(*args)
14
+ Class.new do
15
+ def file(*args)
16
+ Class.new do
17
+ def download(*args)
18
+ end
19
+ end.new
20
+ end
21
+ end.new
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ module Bindan
29
+ module Provider
30
+ class Storage
31
+ class FileNotExist < Error; end
32
+
33
+ #
34
+ # @param [String] bucket
35
+ # @param [String] project_id
36
+ # @param [String] separator
37
+ # @param [String] credentials
38
+ # @param [Google::Cloud::Storage] sdk
39
+ #
40
+ def initialize(bucket, raise_error: nil, separator: "-", sdk: ::Google::Cloud::Storage, **kwargs)
41
+ @_options = {}
42
+ @bucket = bucket
43
+
44
+ @_options[:raise_error] = raise_error
45
+ @separator = separator
46
+ @project_id = kwargs[:project_id]
47
+
48
+ options = prepare_options(kwargs)
49
+
50
+ @_storage = sdk.new(**options)
51
+ end
52
+ attr_reader :project_id, :separator
53
+
54
+ #
55
+ # @param [Hash] options
56
+ # @return [Hash]
57
+ #
58
+ def prepare_options(options)
59
+ if ENV["STORAGE_EMULATOR_HOST"]
60
+ u = URI(ENV["STORAGE_EMULATOR_HOST"].to_s)
61
+ u.path = "/" if u.path.to_s.size == 0
62
+ options[:endpoint] = u.to_s
63
+ end
64
+
65
+ options
66
+ end
67
+
68
+ #
69
+ # decorated bucket name
70
+ #
71
+ # @return [String]
72
+ #
73
+ def bucket
74
+ [@project_id, @bucket].join(@separator)
75
+ end
76
+
77
+ #
78
+ # @raise FileNotExist
79
+ # @param [String] file
80
+ # @return [String]
81
+ #
82
+ def [](file)
83
+ remote = @_storage.bucket(bucket).file(file)
84
+
85
+ if remote
86
+ Tempfile.open { |t|
87
+ remote.download(t.path)
88
+ t.read.chomp
89
+ }
90
+ elsif @_options[:raise_error]
91
+ raise FileNotExist.new file
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1 @@
1
+ Dir.glob(File.join(__dir__.to_s, "providers/*.rb")).each { |f| require_relative f }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bindan
4
+ VERSION = "0.1.0"
5
+ end
data/lib/bindan.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+ require_relative "bindan/version"
5
+ require_relative "bindan/error"
6
+ require_relative "bindan/providers"
7
+
8
+ module Bindan
9
+ #
10
+ # @param [Hash[Symbol, Provider]] providers
11
+ # @param [Proc] block
12
+ # @return [OpenStruct]
13
+ #
14
+ def configure(providers: {env: Bindan::Provider::Envvar.new}, &block)
15
+ if block.is_a? Proc
16
+ container = OpenStruct.new
17
+ block.call(container, Struct.new(*providers.keys).new(*providers.values)) # steep:ignore
18
+ container
19
+ else
20
+ warn "no block given for `configure'"
21
+ end
22
+ end
23
+ module_function :configure
24
+ end
@@ -0,0 +1,328 @@
1
+ ---
2
+ path: ".gem_rbs_collection"
3
+ gems:
4
+ - name: activesupport
5
+ version: '7.0'
6
+ source:
7
+ type: git
8
+ name: ruby/gem_rbs_collection
9
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
10
+ remote: https://github.com/ruby/gem_rbs_collection.git
11
+ repo_dir: gems
12
+ - name: addressable
13
+ version: '2.8'
14
+ source:
15
+ type: git
16
+ name: ruby/gem_rbs_collection
17
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
18
+ remote: https://github.com/ruby/gem_rbs_collection.git
19
+ repo_dir: gems
20
+ - name: ast
21
+ version: '2.4'
22
+ source:
23
+ type: git
24
+ name: ruby/gem_rbs_collection
25
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
26
+ remote: https://github.com/ruby/gem_rbs_collection.git
27
+ repo_dir: gems
28
+ - name: base64
29
+ version: 0.3.0
30
+ source:
31
+ type: rubygems
32
+ - name: benchmark
33
+ version: '0'
34
+ source:
35
+ type: stdlib
36
+ - name: bigdecimal
37
+ version: '3.1'
38
+ source:
39
+ type: git
40
+ name: ruby/gem_rbs_collection
41
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
42
+ remote: https://github.com/ruby/gem_rbs_collection.git
43
+ repo_dir: gems
44
+ - name: concurrent-ruby
45
+ version: '1.1'
46
+ source:
47
+ type: git
48
+ name: ruby/gem_rbs_collection
49
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
50
+ remote: https://github.com/ruby/gem_rbs_collection.git
51
+ repo_dir: gems
52
+ - name: connection_pool
53
+ version: '2.4'
54
+ source:
55
+ type: git
56
+ name: ruby/gem_rbs_collection
57
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
58
+ remote: https://github.com/ruby/gem_rbs_collection.git
59
+ repo_dir: gems
60
+ - name: csv
61
+ version: '3.3'
62
+ source:
63
+ type: git
64
+ name: ruby/gem_rbs_collection
65
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
66
+ remote: https://github.com/ruby/gem_rbs_collection.git
67
+ repo_dir: gems
68
+ - name: date
69
+ version: '0'
70
+ source:
71
+ type: stdlib
72
+ - name: digest
73
+ version: '0'
74
+ source:
75
+ type: stdlib
76
+ - name: erb
77
+ version: '0'
78
+ source:
79
+ type: stdlib
80
+ - name: faraday
81
+ version: '2.7'
82
+ source:
83
+ type: git
84
+ name: ruby/gem_rbs_collection
85
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
86
+ remote: https://github.com/ruby/gem_rbs_collection.git
87
+ repo_dir: gems
88
+ - name: ffi
89
+ version: 1.17.2
90
+ source:
91
+ type: rubygems
92
+ - name: fileutils
93
+ version: '0'
94
+ source:
95
+ type: stdlib
96
+ - name: forwardable
97
+ version: '0'
98
+ source:
99
+ type: stdlib
100
+ - name: google-apis-core
101
+ version: '0.15'
102
+ source:
103
+ type: git
104
+ name: ruby/gem_rbs_collection
105
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
106
+ remote: https://github.com/ruby/gem_rbs_collection.git
107
+ repo_dir: gems
108
+ - name: google-cloud-errors
109
+ version: '1.5'
110
+ source:
111
+ type: git
112
+ name: ruby/gem_rbs_collection
113
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
114
+ remote: https://github.com/ruby/gem_rbs_collection.git
115
+ repo_dir: gems
116
+ - name: googleauth
117
+ version: '1.11'
118
+ source:
119
+ type: git
120
+ name: ruby/gem_rbs_collection
121
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
122
+ remote: https://github.com/ruby/gem_rbs_collection.git
123
+ repo_dir: gems
124
+ - name: httpclient
125
+ version: '2.8'
126
+ source:
127
+ type: git
128
+ name: ruby/gem_rbs_collection
129
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
130
+ remote: https://github.com/ruby/gem_rbs_collection.git
131
+ repo_dir: gems
132
+ - name: i18n
133
+ version: '1.10'
134
+ source:
135
+ type: git
136
+ name: ruby/gem_rbs_collection
137
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
138
+ remote: https://github.com/ruby/gem_rbs_collection.git
139
+ repo_dir: gems
140
+ - name: json
141
+ version: '0'
142
+ source:
143
+ type: stdlib
144
+ - name: jwt
145
+ version: '2.5'
146
+ source:
147
+ type: git
148
+ name: ruby/gem_rbs_collection
149
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
150
+ remote: https://github.com/ruby/gem_rbs_collection.git
151
+ repo_dir: gems
152
+ - name: listen
153
+ version: '3.9'
154
+ source:
155
+ type: git
156
+ name: ruby/gem_rbs_collection
157
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
158
+ remote: https://github.com/ruby/gem_rbs_collection.git
159
+ repo_dir: gems
160
+ - name: logger
161
+ version: '0'
162
+ source:
163
+ type: stdlib
164
+ - name: mini_mime
165
+ version: '0.1'
166
+ source:
167
+ type: git
168
+ name: ruby/gem_rbs_collection
169
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
170
+ remote: https://github.com/ruby/gem_rbs_collection.git
171
+ repo_dir: gems
172
+ - name: minitest
173
+ version: '5.25'
174
+ source:
175
+ type: git
176
+ name: ruby/gem_rbs_collection
177
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
178
+ remote: https://github.com/ruby/gem_rbs_collection.git
179
+ repo_dir: gems
180
+ - name: monitor
181
+ version: '0'
182
+ source:
183
+ type: stdlib
184
+ - name: mutex_m
185
+ version: 0.3.0
186
+ source:
187
+ type: rubygems
188
+ - name: net-http
189
+ version: '0'
190
+ source:
191
+ type: stdlib
192
+ - name: net-protocol
193
+ version: '0'
194
+ source:
195
+ type: stdlib
196
+ - name: openssl
197
+ version: '0'
198
+ source:
199
+ type: stdlib
200
+ - name: optparse
201
+ version: '0'
202
+ source:
203
+ type: stdlib
204
+ - name: parallel
205
+ version: '1.20'
206
+ source:
207
+ type: git
208
+ name: ruby/gem_rbs_collection
209
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
210
+ remote: https://github.com/ruby/gem_rbs_collection.git
211
+ repo_dir: gems
212
+ - name: parser
213
+ version: '3.2'
214
+ source:
215
+ type: git
216
+ name: ruby/gem_rbs_collection
217
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
218
+ remote: https://github.com/ruby/gem_rbs_collection.git
219
+ repo_dir: gems
220
+ - name: pathname
221
+ version: '0'
222
+ source:
223
+ type: stdlib
224
+ - name: prism
225
+ version: 1.4.0
226
+ source:
227
+ type: rubygems
228
+ - name: rainbow
229
+ version: '3.0'
230
+ source:
231
+ type: git
232
+ name: ruby/gem_rbs_collection
233
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
234
+ remote: https://github.com/ruby/gem_rbs_collection.git
235
+ repo_dir: gems
236
+ - name: rake
237
+ version: '13.0'
238
+ source:
239
+ type: git
240
+ name: ruby/gem_rbs_collection
241
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
242
+ remote: https://github.com/ruby/gem_rbs_collection.git
243
+ repo_dir: gems
244
+ - name: rbs
245
+ version: 3.9.4
246
+ source:
247
+ type: rubygems
248
+ - name: rdoc
249
+ version: '0'
250
+ source:
251
+ type: stdlib
252
+ - name: regexp_parser
253
+ version: '2.8'
254
+ source:
255
+ type: git
256
+ name: ruby/gem_rbs_collection
257
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
258
+ remote: https://github.com/ruby/gem_rbs_collection.git
259
+ repo_dir: gems
260
+ - name: rubocop
261
+ version: '1.57'
262
+ source:
263
+ type: git
264
+ name: ruby/gem_rbs_collection
265
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
266
+ remote: https://github.com/ruby/gem_rbs_collection.git
267
+ repo_dir: gems
268
+ - name: rubocop-ast
269
+ version: '1.30'
270
+ source:
271
+ type: git
272
+ name: ruby/gem_rbs_collection
273
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
274
+ remote: https://github.com/ruby/gem_rbs_collection.git
275
+ repo_dir: gems
276
+ - name: securerandom
277
+ version: '0'
278
+ source:
279
+ type: stdlib
280
+ - name: signet
281
+ version: '0.19'
282
+ source:
283
+ type: git
284
+ name: ruby/gem_rbs_collection
285
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
286
+ remote: https://github.com/ruby/gem_rbs_collection.git
287
+ repo_dir: gems
288
+ - name: singleton
289
+ version: '0'
290
+ source:
291
+ type: stdlib
292
+ - name: socket
293
+ version: '0'
294
+ source:
295
+ type: stdlib
296
+ - name: stringio
297
+ version: '0'
298
+ source:
299
+ type: stdlib
300
+ - name: strscan
301
+ version: '0'
302
+ source:
303
+ type: stdlib
304
+ - name: time
305
+ version: '0'
306
+ source:
307
+ type: stdlib
308
+ - name: timeout
309
+ version: '0'
310
+ source:
311
+ type: stdlib
312
+ - name: tsort
313
+ version: '0'
314
+ source:
315
+ type: stdlib
316
+ - name: tzinfo
317
+ version: '2.0'
318
+ source:
319
+ type: git
320
+ name: ruby/gem_rbs_collection
321
+ revision: 4873ad046b4ea8931591626cd547becae6d1e84e
322
+ remote: https://github.com/ruby/gem_rbs_collection.git
323
+ repo_dir: gems
324
+ - name: uri
325
+ version: '0'
326
+ source:
327
+ type: stdlib
328
+ gemfile_lock_path: Gemfile.lock
@@ -0,0 +1,19 @@
1
+ # Download sources
2
+ sources:
3
+ - type: git
4
+ name: ruby/gem_rbs_collection
5
+ remote: https://github.com/ruby/gem_rbs_collection.git
6
+ revision: main
7
+ repo_dir: gems
8
+
9
+ # You can specify local directories as sources also.
10
+ # - type: local
11
+ # path: path/to/your/local/repository
12
+
13
+ # A directory to install the downloaded RBSs
14
+ path: .gem_rbs_collection
15
+
16
+ gems:
17
+ # If you want to avoid installing rbs files for gems, you can specify them here.
18
+ - name: google-cloud-firestore
19
+ ignore: true
@@ -0,0 +1,76 @@
1
+ module Bindan
2
+ module Emulator
3
+ #
4
+ # Represents and controls a single instance of the Google Cloud Firestore emulator process.
5
+ # This class encapsulates the logic for starting, stopping, and waiting for the emulator,
6
+ # separating process management from the test execution flow.
7
+ #
8
+ class FirestoreController
9
+ @pid: untyped
10
+
11
+ @host: untyped
12
+
13
+ @port: untyped
14
+
15
+ WAIT_TIMEOUT: 15
16
+
17
+ INITIAL_BACKOFF_KEY_SEC: ::Float
18
+
19
+ BACKOFF_MULTIPLIER: ::Float
20
+
21
+ #
22
+ # @return [Array<String, Integer>]
23
+ #
24
+ def self.host_and_port: (?untyped? host, ?untyped? port) -> ::Array[untyped]
25
+
26
+ #
27
+ # Initiates the emulator process and returns a new instance.
28
+ #
29
+ # @param [String] import
30
+ # @param [String] export
31
+ # @param [String] host
32
+ # @param [Integer] port
33
+ # @param [bool] close_io
34
+ # @raise [Errno]
35
+ # @return [FirestoreEmulatorController] An instance to manage the emulator lifecycle.
36
+ #
37
+ def self.start: (?import: untyped?, ?export: untyped?, ?host: untyped?, ?port: untyped?, ?close_io: bool) -> untyped
38
+
39
+ #
40
+ # kill process group
41
+ #
42
+ # @param [Integer] pid
43
+ # @param [bool] with_message
44
+ # @return [void]
45
+ #
46
+ def self.stop: (untyped pid, ?with_message: bool) -> untyped
47
+
48
+ #
49
+ # @param [Integer] host
50
+ # @param [Integer] port
51
+ #
52
+ def self.kill_process_if_already_exists: (host: untyped, port: untyped, ?with_message: bool) -> untyped
53
+
54
+ #
55
+ # @param [Integer] pid - process group id
56
+ #
57
+ def initialize: (untyped pid, untyped host, untyped port) -> void
58
+
59
+ #
60
+ # waits to accessable
61
+ #
62
+ # @raise [Timeout::Error] if the emulator does not become available within the configured timeout.
63
+ # @param [number] timeout
64
+ # @param [number] backoff
65
+ # @param [number] multiplier
66
+ # @return [void]
67
+ #
68
+ def wait_available: (?timeout: untyped, ?backoff: untyped, ?multiplier: untyped, ?with_message: bool) -> untyped
69
+
70
+ #
71
+ # @return [void]
72
+ #
73
+ def stop: (?with_message: bool) -> untyped
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,71 @@
1
+ module Bindan
2
+ module Emulator
3
+ class GcsServerController
4
+ @container_name: untyped
5
+
6
+ @folder: untyped
7
+
8
+ class ContainerCannotOpenError < Error
9
+ end
10
+
11
+ CONTAINER_NAME: "gcs-server"
12
+
13
+ WAIT_TIMEOUT: 15
14
+
15
+ INITIAL_BACKOFF_KEY_SEC: ::Float
16
+
17
+ BACKOFF_MULTIPLIER: ::Float
18
+
19
+ #
20
+ # @raise [Errno]
21
+ # @param [String] folder
22
+ # @param [Integer] [port]
23
+ # @param [String] [name]
24
+ # @return [GcsServerController]
25
+ #
26
+ def self.start: (folder: untyped, ?port: ::Integer, ?name: untyped, ?close_io: bool) -> untyped
27
+
28
+ #
29
+ # @raise [IOError]
30
+ # @param [String] name
31
+ # @return [bool]
32
+ #
33
+ def self.running?: (name: untyped) -> untyped
34
+
35
+ #
36
+ # @param [String] name
37
+ # @raise [Errno]
38
+ # @return [void]
39
+ #
40
+ def self.stop: (name: untyped) -> untyped
41
+
42
+ #
43
+ # @param [String] name
44
+ # @param [String] folder
45
+ #
46
+ def initialize: (name: untyped, folder: untyped) -> void
47
+
48
+ #
49
+ # @return
50
+ #
51
+ def stop: () -> untyped
52
+
53
+ #
54
+ # @param [String] name
55
+ # @return [bool]
56
+ #
57
+ def running?: () -> untyped
58
+
59
+ #
60
+ # waits container to be running
61
+ #
62
+ # @raise [Timeout::Error] if the container does not become available within the configured timeout.
63
+ # @param [number] timeout
64
+ # @param [number] backoff
65
+ # @param [number] multiplier
66
+ # @return [void]
67
+ #
68
+ def wait_available: (?timeout: untyped, ?backoff: untyped, ?multiplier: untyped) -> untyped
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,4 @@
1
+ module Bindan
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module Bindan
2
+ module Provider
3
+ class Envvar
4
+ @_env: Hash[String, String]
5
+
6
+ @_options: Hash[untyped, untyped]
7
+
8
+ #
9
+ # @param [Hash] env
10
+ # @param [Hash] options
11
+ #
12
+ def initialize: (?::Hash[String, String] env, ?::Hash[untyped, untyped] options) -> void
13
+
14
+ #
15
+ # @raise KeyError
16
+ # @param [String] key
17
+ # @return [String]
18
+ #
19
+ def []: (String key) -> untyped
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,47 @@
1
+ module Google
2
+ module Cloud
3
+ class Firestore
4
+ def initialize: (**untyped kwargs) -> void
5
+
6
+ def doc: (*untyped args) -> untyped
7
+ end
8
+ end
9
+ end
10
+
11
+ module Bindan
12
+ module Provider
13
+ class Firestore
14
+ @_options: Hash[Symbol, untyped]
15
+
16
+ @collection: String
17
+
18
+ @project_id: String
19
+
20
+ @_firestore: Google::Cloud::Firestore
21
+
22
+ class ColOrDocNotExist < Error
23
+ end
24
+
25
+ #
26
+ # @param [String] collection
27
+ # @param [bool] raise_error
28
+ # @param [Google::Cloud::Firestore] sdk
29
+ #
30
+ def initialize: (?String? collection, ?project_id: String?, ?raise_error: bool, ?sdk: untyped, **untyped kwargs) -> void
31
+
32
+ attr_reader project_id: String
33
+
34
+ #
35
+ # @param [Hash] pair
36
+ #
37
+ def _prepare: (Hash[String, untyped] pair) -> untyped
38
+
39
+ #
40
+ # @raise ColOrDocNotExist
41
+ # @param [String] key
42
+ # @return [Hash]
43
+ #
44
+ def []: (String key) -> untyped
45
+ end
46
+ end
47
+ end