go_dbscan_filter_binary 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ad0debca08e183d3253a52f7df2694b383eb95036978a538357c6e486cdabae
4
+ data.tar.gz: 2fca6e1bdf9cb4fd1bfaa5a6458000476abbd40971078732faa35d414cf84ab1
5
+ SHA512:
6
+ metadata.gz: 11347d45885b847ee2da87edc51d0f9602928b50f17da6a5a95534170868de64afa7890bc825caa8a3b91504764baac0367954c061e015889e69282423098a3c
7
+ data.tar.gz: ddfec33d952a6fb5429532af6299505068cbf45749a89fc7bd5e8501745ff88a3b70c7ab058e9f3d726f676e6291e07d6e2ef41cc05eaf9a47a15814c432a833
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sergey Kovalev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # GoDbscanFilterBinary
2
+
3
+ A Ruby gem that provides the `go_dbscan_filter` binary for DBSCAN geo point clustering. The gem automatically downloads the correct platform-specific binary during installation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'go_dbscan_filter_binary'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install go_dbscan_filter_binary
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ After installation, you can access the binary path:
28
+
29
+ ```ruby
30
+ require 'go_dbscan_filter_binary'
31
+
32
+ # Get the binary path
33
+ binary_path = GoDbscanFilterBinary.binary_path
34
+
35
+ # Check if binary exists
36
+ if GoDbscanFilterBinary.binary_exists?
37
+ system("#{GoDbscanFilterBinary.binary!} -input points.csv -output filtered.csv")
38
+ end
39
+
40
+ # Or use the executable directly
41
+ system("go_dbscan_filter -input points.csv -output filtered.csv")
42
+ ```
43
+
44
+ ## Supported Platforms
45
+
46
+ - Linux (amd64, arm64)
47
+ - macOS (darwin) (amd64, arm64)
48
+ - Windows (amd64, arm64)
49
+
50
+ The gem automatically detects your platform and downloads the appropriate binary from GitHub releases.
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake build` to build the gem.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
61
+
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'go_dbscan_filter_binary'
5
+
6
+ binary_path = GoDbscanFilterBinary.binary!
7
+
8
+ exec(binary_path, *ARGV)
9
+
@@ -0,0 +1,287 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'json'
7
+ require 'zlib'
8
+ require 'stringio'
9
+ require 'tempfile'
10
+ require 'open-uri'
11
+
12
+ # Determine platform
13
+ def detect_platform
14
+ os = case RbConfig::CONFIG['host_os']
15
+ when /linux/i
16
+ 'linux'
17
+ when /darwin|mac os/i
18
+ 'darwin'
19
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/i
20
+ 'windows'
21
+ else
22
+ raise "Unsupported OS: #{RbConfig::CONFIG['host_os']}"
23
+ end
24
+
25
+ arch = case RbConfig::CONFIG['host_cpu']
26
+ when /x86_64|amd64/i
27
+ 'amd64'
28
+ when /arm64|aarch64/i
29
+ 'arm64'
30
+ else
31
+ raise "Unsupported architecture: #{RbConfig::CONFIG['host_cpu']}"
32
+ end
33
+
34
+ [os, arch]
35
+ end
36
+
37
+ # Get the gem version (should match the release version)
38
+ def get_gem_version
39
+ # When installed, extconf.rb runs in: gem_dir/ext/go_dbscan_filter_binary/extconf.rb
40
+ # We need to find: gem_dir/lib/go_dbscan_filter_binary/version.rb
41
+
42
+ # Calculate gem root: go up two directory levels from extconf.rb
43
+ # Use expand_path to ensure we get absolute path
44
+ extconf_dir = File.expand_path(File.dirname(__FILE__))
45
+ # extconf_dir = gem_dir/ext/go_dbscan_filter_binary
46
+ ext_dir = File.expand_path('..', extconf_dir)
47
+ # ext_dir = gem_dir/ext
48
+ gem_root = File.expand_path('..', ext_dir)
49
+ # gem_root = gem_dir
50
+
51
+ version_file = File.join(gem_root, 'lib', 'go_dbscan_filter_binary', 'version.rb')
52
+
53
+ # Try to load the version file directly
54
+ if File.exist?(version_file)
55
+ version_content = File.read(version_file)
56
+ if version_content =~ /VERSION\s*=\s*['"]([^'"]+)['"]/
57
+ return $1
58
+ end
59
+ end
60
+
61
+ # Fallback: try to require it
62
+ begin
63
+ $LOAD_PATH.unshift(File.join(gem_root, 'lib'))
64
+ require 'go_dbscan_filter_binary/version'
65
+ return GoDbscanFilterBinary::VERSION
66
+ rescue LoadError => e
67
+ raise "Could not determine gem version. Tried: #{version_file} (gem_root: #{gem_root}, extconf_dir: #{extconf_dir})"
68
+ end
69
+ end
70
+
71
+ # Extract tar.gz using system tar command (more reliable)
72
+ def extract_tar_gz(data, binary_name, output_path)
73
+ require 'tempfile'
74
+ temp_tar = Tempfile.new(['binary', '.tar.gz'])
75
+ temp_tar.binmode
76
+ temp_tar.write(data)
77
+ temp_tar.close
78
+
79
+ # Create temp directory for extraction
80
+ temp_dir = Dir.mktmpdir('go_dbscan_filter_extract')
81
+ begin
82
+ # Extract entire archive to temp directory
83
+ if system("tar -xzf '#{temp_tar.path}' -C '#{temp_dir}' 2>/dev/null")
84
+ # Find the binary in the extracted files (could be at root or in subdirectory)
85
+ found_binary = nil
86
+ Dir.glob(File.join(temp_dir, '**', binary_name)).each do |file|
87
+ if File.file?(file) && File.executable?(file) || true # Accept any file matching the name
88
+ found_binary = file
89
+ break
90
+ end
91
+ end
92
+
93
+ # Also check root level
94
+ root_binary = File.join(temp_dir, binary_name)
95
+ found_binary = root_binary if File.exist?(root_binary) && !found_binary
96
+
97
+ if found_binary && File.exist?(found_binary)
98
+ FileUtils.cp(found_binary, output_path)
99
+ File.chmod(0o755, output_path)
100
+ temp_tar.unlink
101
+ return true
102
+ end
103
+ end
104
+ ensure
105
+ FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
106
+ end
107
+
108
+ # Fallback: manual extraction
109
+ io = StringIO.new(data)
110
+ gz = Zlib::GzipReader.new(io)
111
+ tar_data = gz.read
112
+ gz.close
113
+
114
+ # Simple tar extraction
115
+ pos = 0
116
+ while pos < tar_data.length
117
+ header = tar_data[pos, 512]
118
+ break if header.nil? || header.empty? || header[0] == "\0"
119
+
120
+ name = header[0, 100].strip
121
+ size_str = header[124, 12].strip
122
+ size = size_str.oct rescue 0
123
+
124
+ pos += 512
125
+
126
+ if name.end_with?(binary_name) && size > 0
127
+ binary_data = tar_data[pos, size]
128
+ File.open(output_path, 'wb') do |f|
129
+ f.write(binary_data)
130
+ end
131
+ File.chmod(0o755, output_path)
132
+ temp_tar.unlink
133
+ return true
134
+ end
135
+
136
+ pos += (size + 511) / 512 * 512
137
+ end
138
+
139
+ temp_tar.unlink
140
+ false
141
+ end
142
+
143
+ # Extract zip using system unzip command (more reliable)
144
+ def extract_zip(data, binary_name, output_path)
145
+ require 'tempfile'
146
+ temp_zip = Tempfile.new(['binary', '.zip'])
147
+ temp_zip.binmode
148
+ temp_zip.write(data)
149
+ temp_zip.close
150
+
151
+ # Create temp directory for extraction
152
+ temp_dir = Dir.mktmpdir('go_dbscan_filter_extract')
153
+ begin
154
+ # Extract entire archive to temp directory
155
+ if system("unzip -q '#{temp_zip.path}' -d '#{temp_dir}' 2>/dev/null")
156
+ # Find the binary in the extracted files
157
+ found_binary = nil
158
+ Dir.glob(File.join(temp_dir, '**', binary_name)).each do |file|
159
+ if File.file?(file)
160
+ found_binary = file
161
+ break
162
+ end
163
+ end
164
+
165
+ # Also check root level
166
+ root_binary = File.join(temp_dir, binary_name)
167
+ found_binary = root_binary if File.exist?(root_binary) && !found_binary
168
+
169
+ if found_binary && File.exist?(found_binary)
170
+ FileUtils.cp(found_binary, output_path)
171
+ temp_zip.unlink
172
+ return true
173
+ end
174
+ end
175
+
176
+ # Fallback: try direct extraction to output directory
177
+ if system("unzip -q -j '#{temp_zip.path}' '*#{binary_name}' -d '#{File.dirname(output_path)}' 2>/dev/null")
178
+ result = File.exist?(output_path)
179
+ temp_zip.unlink
180
+ return result
181
+ end
182
+ ensure
183
+ FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
184
+ end
185
+
186
+ temp_zip.unlink
187
+ false
188
+ end
189
+
190
+ # Download and extract the binary
191
+ def download_binary(os, arch, version)
192
+ puts "Downloading go_dbscan_filter binary for #{os}/#{arch}..."
193
+
194
+ # Construct download URL
195
+ archive_name = "go-dbscan-filter_#{os}_#{arch}"
196
+ archive_name += '.zip' if os == 'windows'
197
+ archive_name += '.tar.gz' unless os == 'windows'
198
+
199
+ url = "https://github.com/serg-kovalev/go-dbscan-filter/releases/download/v#{version}/#{archive_name}"
200
+
201
+ puts "Downloading from: #{url}"
202
+
203
+ # Download the archive (open-uri handles redirects automatically)
204
+ begin
205
+ response_body = URI.open(url, 'User-Agent' => 'go_dbscan_filter_binary-gem', &:read)
206
+ rescue OpenURI::HTTPError => e
207
+ raise "Failed to download binary: HTTP #{e.io.status[0]} #{e.io.status[1]}"
208
+ rescue => e
209
+ raise "Failed to download binary: #{e.message}"
210
+ end
211
+
212
+ # Determine binary name
213
+ binary_name = 'go_dbscan_filter'
214
+ binary_name += '.exe' if os == 'windows'
215
+
216
+ # Download binary to lib/go_dbscan_filter_binary/bin/ (wrapper script stays in bin/)
217
+ # From ext/go_dbscan_filter_binary/extconf.rb, go up to gem root
218
+ gem_root = File.expand_path('../..', File.dirname(__FILE__))
219
+ bin_dir = File.join(gem_root, 'lib', 'go_dbscan_filter_binary', 'bin')
220
+ FileUtils.mkdir_p(bin_dir)
221
+ output_path = File.join(bin_dir, binary_name)
222
+
223
+ # Extract binary
224
+ success = if os == 'windows'
225
+ extract_zip(response_body, binary_name, output_path)
226
+ else
227
+ extract_tar_gz(response_body, binary_name, output_path)
228
+ end
229
+
230
+ unless success && File.exist?(output_path)
231
+ raise "Binary #{binary_name} was not extracted correctly"
232
+ end
233
+
234
+ puts "Binary downloaded successfully to #{output_path}"
235
+ output_path
236
+ end
237
+
238
+ # Main installation logic
239
+ begin
240
+ os, arch = detect_platform
241
+ version = get_gem_version
242
+
243
+ puts "Installing go_dbscan_filter binary for platform: #{os}/#{arch}"
244
+ puts "Gem version: #{version} (will download matching release v#{version})"
245
+
246
+ binary_path = download_binary(os, arch, version)
247
+
248
+ # Determine binary name for Makefile
249
+ binary_name = 'go_dbscan_filter'
250
+ binary_name += '.exe' if os == 'windows'
251
+
252
+ # Get bin directory path (actual binary is in lib/go_dbscan_filter_binary/bin/)
253
+ gem_root = File.expand_path('../..', File.dirname(__FILE__))
254
+ bin_dir = File.join(gem_root, 'lib', 'go_dbscan_filter_binary', 'bin')
255
+ bin_path = File.join(bin_dir, binary_name)
256
+
257
+ # Create Makefile (required by RubyGems)
258
+ File.open('Makefile', 'w') do |f|
259
+ f.puts <<~MAKEFILE
260
+ # Makefile for go_dbscan_filter_binary extension
261
+ # The binary is already downloaded by extconf.rb
262
+
263
+ .PHONY: all install clean
264
+
265
+ all:
266
+ \t@echo "Binary already prepared by extconf.rb"
267
+ \t@test -f "#{bin_path}" || (echo "Error: Binary not found at #{bin_path}" && exit 1)
268
+ \t@echo "Binary verified: #{bin_path}"
269
+
270
+ install: all
271
+ \t@echo "Installing go_dbscan_filter binary..."
272
+ \t@test -f "#{bin_path}" || (echo "Error: Binary not found at #{bin_path}" && exit 1)
273
+ \t@chmod +x "#{bin_path}" 2>/dev/null || true
274
+ \t@echo "Binary installed successfully: #{bin_path}"
275
+
276
+ clean:
277
+ \t@echo "Cleaning up..."
278
+ \t@# Don't remove Makefile - it's needed for make install
279
+ MAKEFILE
280
+ end
281
+
282
+ rescue => e
283
+ $stderr.puts "Error installing binary: #{e.message}"
284
+ $stderr.puts e.backtrace.join("\n")
285
+ exit 1
286
+ end
287
+
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/go_dbscan_filter_binary/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'go_dbscan_filter_binary'
7
+ spec.version = GoDbscanFilterBinary::VERSION
8
+ spec.authors = ['Sergey Kovalev']
9
+ spec.email = ['serg-kovalev@users.noreply.github.com>']
10
+
11
+ spec.summary = 'DBSCAN geo point clustering binary'
12
+ spec.description = 'Provides the go-dbscan-filter binary to be used by other gems'
13
+ spec.homepage = 'https://github.com/serg-kovalev/go-dbscan-filter'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir['lib/**/*', 'ext/**/*', 'bin/**/*', '*.md', 'LICENSE', '*.gemspec']
17
+ # Note: bin/go_dbscan_filter is a Ruby wrapper script that calls the actual Go binary
18
+ # The actual Go binary is downloaded to lib/go_dbscan_filter_binary/bin/ during installation via extconf.rb
19
+ spec.bindir = 'bin'
20
+ spec.executables = ['go_dbscan_filter']
21
+ # The executable is the actual Go binary downloaded during installation
22
+ spec.require_paths = ['lib']
23
+ spec.extensions = ['ext/go_dbscan_filter_binary/extconf.rb']
24
+
25
+ spec.required_ruby_version = '>= 2.7.0'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 2.0'
28
+ spec.add_development_dependency 'rake', '~> 13.0'
29
+ end
30
+
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoDbscanFilterBinary
4
+ VERSION = '0.1.2'
5
+ end
6
+
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'go_dbscan_filter_binary/version'
4
+
5
+ module GoDbscanFilterBinary
6
+ class Error < StandardError; end
7
+
8
+ # Returns the path to the go_dbscan_filter binary
9
+ def self.binary_path
10
+ @binary_path ||= begin
11
+ # Find the gem's root directory
12
+ # __dir__ points to lib/go_dbscan_filter_binary, so go up two levels to gem root
13
+ gem_root = File.expand_path('../..', __dir__)
14
+
15
+ # Construct binary path (actual binary is in lib/go_dbscan_filter_binary/bin/)
16
+ binary_name = 'go_dbscan_filter'
17
+ binary_name += '.exe' if Gem.win_platform?
18
+ bin_path = File.join(__dir__, 'bin', binary_name)
19
+
20
+ # Verify the path exists, if not try alternative methods
21
+ unless File.exist?(bin_path)
22
+ # Try using Gem to find the gem path (works for installed gems)
23
+ begin
24
+ spec = Gem::Specification.find_by_name('go_dbscan_filter_binary')
25
+ if spec
26
+ bin_path = File.join(spec.gem_dir, 'lib', 'go_dbscan_filter_binary', 'bin', binary_name)
27
+ end
28
+ rescue Gem::LoadError
29
+ # Gem not found via Gem, try Bundler
30
+ begin
31
+ require 'bundler'
32
+ if defined?(Bundler)
33
+ spec = Bundler.rubygems.find_name('go_dbscan_filter_binary').first
34
+ if spec
35
+ bin_path = File.join(spec.full_gem_path, 'lib', 'go_dbscan_filter_binary', 'bin', binary_name)
36
+ end
37
+ end
38
+ rescue
39
+ # Fallback to original calculation
40
+ end
41
+ end
42
+ end
43
+
44
+ bin_path
45
+ end
46
+ end
47
+
48
+ # Returns true if the binary exists
49
+ def self.binary_exists?
50
+ File.exist?(binary_path) && File.executable?(binary_path)
51
+ end
52
+
53
+ # Returns the binary path or raises an error if it doesn't exist
54
+ def self.binary!
55
+ raise Error, "go_dbscan_filter binary not found at #{binary_path}" unless binary_exists?
56
+ binary_path
57
+ end
58
+ end
59
+
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go_dbscan_filter_binary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Kovalev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ description: Provides the go-dbscan-filter binary to be used by other gems
42
+ email:
43
+ - serg-kovalev@users.noreply.github.com>
44
+ executables:
45
+ - go_dbscan_filter
46
+ extensions:
47
+ - ext/go_dbscan_filter_binary/extconf.rb
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE
51
+ - README.md
52
+ - bin/go_dbscan_filter
53
+ - ext/go_dbscan_filter_binary/extconf.rb
54
+ - go_dbscan_filter_binary.gemspec
55
+ - lib/go_dbscan_filter_binary.rb
56
+ - lib/go_dbscan_filter_binary/version.rb
57
+ homepage: https://github.com/serg-kovalev/go-dbscan-filter
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.7.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.5.22
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: DBSCAN geo point clustering binary
80
+ test_files: []