Class: JsonStructure::BinaryInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonstructure/binary_installer.rb

Overview

Downloads and installs pre-built C library binaries from GitHub releases

Constant Summary collapse

REPO =
'json-structure/sdk'
DEFAULT_VERSION =
'v0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version: nil) ⇒ BinaryInstaller

Returns a new instance of BinaryInstaller.



16
17
18
19
20
# File 'lib/jsonstructure/binary_installer.rb', line 16

def initialize(version: nil)
  @version = version || DEFAULT_VERSION
  @platform = detect_platform
  @lib_dir = File.expand_path('../../ext', __dir__)
end

Instance Attribute Details

#lib_dirObject (readonly)

Returns the value of attribute lib_dir.



14
15
16
# File 'lib/jsonstructure/binary_installer.rb', line 14

def lib_dir
  @lib_dir
end

#platformObject (readonly)

Returns the value of attribute platform.



14
15
16
# File 'lib/jsonstructure/binary_installer.rb', line 14

def platform
  @platform
end

#versionObject (readonly)

Returns the value of attribute version.



14
15
16
# File 'lib/jsonstructure/binary_installer.rb', line 14

def version
  @version
end

Instance Method Details

#binary_exists?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/jsonstructure/binary_installer.rb', line 40

def binary_exists?
  File.exist?(binary_path)
end

#binary_pathObject



44
45
46
# File 'lib/jsonstructure/binary_installer.rb', line 44

def binary_path
  File.join(lib_dir, binary_name)
end

#installObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jsonstructure/binary_installer.rb', line 22

def install
  FileUtils.mkdir_p(lib_dir)

  if binary_exists?
    puts "Binary already installed at #{binary_path}"
    return true
  end

  puts "Downloading C library binary for #{platform}..."
  download_binary
  puts "Binary installed successfully at #{binary_path}"
  true
rescue StandardError => e
  warn "Failed to download binary: #{e.message}"
  warn "You may need to build the C library manually."
  false
end