Module: CardanoUp::Utils
- Defined in:
- lib/cardano-up/utils.rb
Overview
Utility methods
Class Method Summary collapse
- .cmd(cmd, display_result: false) ⇒ Object
- .config_urls(env) ⇒ Object
-
.configs_base_url(env) ⇒ Object
Latest Cardano configs.
-
.get_binary_url(release = 'latest') ⇒ Object
Latest binary url for latest release or particular tag, from master or pr num.
- .latest_tag ⇒ Object
- .linux? ⇒ Boolean
- .mac? ⇒ Boolean
- .wget(url, file = nil) ⇒ Object
- .win? ⇒ Boolean
Class Method Details
.cmd(cmd, display_result: false) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/cardano-up/utils.rb', line 6 def self.cmd(cmd, display_result: false) cmd.gsub(/\s+/, ' ') res = `#{cmd}` puts cmd if display_result puts res if display_result res.gsub("\n", '') end |
.config_urls(env) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cardano-up/utils.rb', line 85 def self.config_urls(env) raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env) base_url = configs_base_url(env) configs = [] CardanoUp::CONFIG_FILES.each do |file| configs << "#{base_url}#{file}" end configs end |
.configs_base_url(env) ⇒ Object
Latest Cardano configs
78 79 80 81 82 |
# File 'lib/cardano-up/utils.rb', line 78 def self.configs_base_url(env) raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env) "#{CardanoUp::CONFIGS_BASE_URL}/#{env}/" end |
.get_binary_url(release = 'latest') ⇒ Object
Latest binary url for latest release or particular tag, from master or pr num.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cardano-up/utils.rb', line 41 def self.get_binary_url(release = 'latest') unless release == 'master' || release == 'latest' || release =~ /^v20.{2}-.{2}-.{2}/ || release =~ /^\d+$/ raise CardanoUp::VersionNotSupportedError, release end url = '' if release == 'latest' || release =~ /^v20.{2}-.{2}-.{2}/ tag = release == 'latest' ? latest_tag : release if linux? file = "cardano-wallet-#{tag}-linux64.tar.gz" elsif mac? file = "cardano-wallet-#{tag}-macos-intel.tar.gz" elsif win? file = "cardano-wallet-#{tag}-win64.zip" end url = "#{CardanoUp::BINS_BASE_URL}/releases/download/#{tag}/#{file}" else if linux? os = 'linux.musl.cardano-wallet-linux64' elsif mac? os = 'macos.intel.cardano-wallet-macos-intel' elsif win? os = 'linux.windows.cardano-wallet-win64' end url = if release == 'master' "#{CardanoUp::HYDRA_BASE_URL}/#{os}/latest/download-by-type/file/binary-dist" else "#{CardanoUp::HYDRA_BASE_URL}-pr-#{release}/#{os}/latest/download-by-type/file/binary-dist" end end url end |
.latest_tag ⇒ Object
32 33 34 35 |
# File 'lib/cardano-up/utils.rb', line 32 def self.latest_tag HTTParty.get("#{CardanoUp::BINS_BASE_URL}/releases/latest", headers: { 'Accept' => 'application/json' })['tag_name'] end |
.linux? ⇒ Boolean
24 25 26 |
# File 'lib/cardano-up/utils.rb', line 24 def self.linux? RUBY_PLATFORM =~ /linux/ end |
.mac? ⇒ Boolean
28 29 30 |
# File 'lib/cardano-up/utils.rb', line 28 def self.mac? RUBY_PLATFORM =~ /darwin/ end |
.wget(url, file = nil) ⇒ Object
14 15 16 17 18 |
# File 'lib/cardano-up/utils.rb', line 14 def self.wget(url, file = nil) file ||= File.basename(url) resp = HTTParty.get(url) File.binwrite(file, resp.body) end |
.win? ⇒ Boolean
20 21 22 |
# File 'lib/cardano-up/utils.rb', line 20 def self.win? RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/ end |