Class: Zui::Client
- Inherits:
-
Object
- Object
- Zui::Client
- Defined in:
- lib/zui/client.rb
Direct Known Subclasses
Constant Summary collapse
- FORMAT =
1- MAX_ARCHIVE_BYTES =
1_073_741_824- MAX_EXPANDED_BYTES =
2_147_483_648- MAX_ENTRIES =
100_000- REDIRECT_LIMIT =
5
Instance Attribute Summary collapse
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #archive_name ⇒ Object
- #archive_url ⇒ Object
- #checksum_url ⇒ Object
- #configure! ⇒ Object
- #configured? ⇒ Boolean
- #copy_to(destination) ⇒ Object
- #environment(base = ENV.to_h, client_root: root) ⇒ Object
- #environment_entries ⇒ Object
- #executable ⇒ Object
- #executable_relative_path ⇒ Object
-
#initialize(platform: Platform.current, version: VERSION, environment: ENV, cache_root: nil, release_base_url: nil, downloader: nil) ⇒ Client
constructor
A new instance of Client.
- #manifest ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(platform: Platform.current, version: VERSION, environment: ENV, cache_root: nil, release_base_url: nil, downloader: nil) ⇒ Client
Returns a new instance of Client.
24 25 26 27 28 29 30 31 32 |
# File 'lib/zui/client.rb', line 24 def initialize(platform: Platform.current, version: VERSION, environment: ENV, cache_root: nil, release_base_url: nil, downloader: nil) @platform = platform.assert_supported! @version = version.to_s @environment = environment @cache_root = cache_root @release_base_url = release_base_url @downloader = downloader || method(:download) end |
Instance Attribute Details
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
22 23 24 |
# File 'lib/zui/client.rb', line 22 def platform @platform end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
22 23 24 |
# File 'lib/zui/client.rb', line 22 def version @version end |
Instance Method Details
#archive_name ⇒ Object
109 |
# File 'lib/zui/client.rb', line 109 def archive_name = "zui-client-#{platform.id}.tar.gz" |
#archive_url ⇒ Object
111 112 113 114 115 116 |
# File 'lib/zui/client.rb', line 111 def archive_url override = @environment["ZUI_CLIENT_ARCHIVE"] return File.(override) if override && !override.empty? URI.join("#{release_base_url}/", archive_name) end |
#checksum_url ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/zui/client.rb', line 118 def checksum_url override = @environment["ZUI_CLIENT_CHECKSUM"] return File.(override) if override && !override.empty? source = archive_url source.is_a?(URI) ? URI("#{source}.sha256") : "#{source}.sha256" end |
#configure! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/zui/client.rb', line 48 def configure! return root if configured? raise ArgumentError, "ZUI_CLIENT_ROOT is not a valid configured client: #{root}" if client_root_override? FileUtils.mkdir_p(File.dirname(root)) File.open("#{root}.lock", File::RDWR | File::CREAT, 0o600) do |lock| lock.flock(File::LOCK_EX) return root if configured? install_download! end root end |
#configured? ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/zui/client.rb', line 41 def configured? validate!(root) true rescue ArgumentError, Errno::ENOENT false end |
#copy_to(destination) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/zui/client.rb', line 91 def copy_to(destination) manifest = validate!(root) raise ArgumentError, "client destination already exists: #{destination}" if File.exist?(destination) created = true FileUtils.mkdir_p(destination) FileUtils.cp_r(Dir.children(root).map { |entry| File.join(root, entry) }, destination) validate!(destination) manifest rescue StandardError FileUtils.remove_entry(destination) if created && destination && File.exist?(destination) raise end |
#environment(base = ENV.to_h, client_root: root) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/zui/client.rb', line 78 def environment(base = ENV.to_h, client_root: root) environment_entries.each_with_object(base.to_h.dup) do |(name, paths), result| unless name.match?(/\A[A-Z][A-Z0-9_]*\z/) raise ArgumentError, "invalid environment variable in Zui client: #{name.inspect}" end resolved = paths.map { |path| File.join(client_root, path) } previous = result[name] resolved << previous unless previous.nil? || previous.empty? result[name] = resolved.join(File::PATH_SEPARATOR) end end |
#environment_entries ⇒ Object
71 72 73 74 75 76 |
# File 'lib/zui/client.rb', line 71 def environment_entries manifest = validate!(root) manifest.fetch("environment", {}).transform_values do |paths| Array(paths).map { |path| safe_manifest_path!(path, "client environment path") } end end |
#executable ⇒ Object
62 63 64 65 |
# File 'lib/zui/client.rb', line 62 def executable manifest = validate!(root) File.join(root, manifest.fetch("executable")) end |
#executable_relative_path ⇒ Object
67 68 69 |
# File 'lib/zui/client.rb', line 67 def executable_relative_path validate!(root).fetch("executable") end |
#manifest ⇒ Object
105 106 107 |
# File 'lib/zui/client.rb', line 105 def manifest validate!(root) end |
#root ⇒ Object
34 35 36 37 38 39 |
# File 'lib/zui/client.rb', line 34 def root override = @environment["ZUI_CLIENT_ROOT"] return File.(override) if override && !override.empty? File.join(cache_root, "zui", "clients", version, platform.id) end |