Class: JsonStructure::BinaryInstaller
- Inherits:
-
Object
- Object
- JsonStructure::BinaryInstaller
- 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
-
#lib_dir ⇒ Object
readonly
Returns the value of attribute lib_dir.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #binary_exists? ⇒ Boolean
- #binary_path ⇒ Object
-
#initialize(version: nil) ⇒ BinaryInstaller
constructor
A new instance of BinaryInstaller.
- #install ⇒ Object
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.('../../ext', __dir__) end |
Instance Attribute Details
#lib_dir ⇒ Object (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 |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
14 15 16 |
# File 'lib/jsonstructure/binary_installer.rb', line 14 def platform @platform end |
#version ⇒ Object (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
40 41 42 |
# File 'lib/jsonstructure/binary_installer.rb', line 40 def binary_exists? File.exist?(binary_path) end |
#binary_path ⇒ Object
44 45 46 |
# File 'lib/jsonstructure/binary_installer.rb', line 44 def binary_path File.join(lib_dir, binary_name) end |
#install ⇒ Object
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.}" warn "You may need to build the C library manually." false end |