Class: Zui::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/zui/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform: Platform.current, environment: ENV, client: nil) ⇒ Host

Returns a new instance of Host.



7
8
9
10
11
# File 'lib/zui/host.rb', line 7

def initialize(platform: Platform.current, environment: ENV, client: nil)
  @platform = platform.assert_supported!
  @environment = environment
  @client = client || Client.new(platform:, environment:)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/zui/host.rb', line 5

def client
  @client
end

#platformObject (readonly)

Returns the value of attribute platform.



5
6
7
# File 'lib/zui/host.rb', line 5

def platform
  @platform
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/zui/host.rb', line 21

def available?
  override = @environment["ZUI_HOST"]
  return File.executable?(File.expand_path(override)) if override && !override.empty?

  client.configured?
end

#configure!Object



28
# File 'lib/zui/host.rb', line 28

def configure! = client.configure!

#environment(base = ENV.to_h) ⇒ Object



30
31
32
33
34
35
# File 'lib/zui/host.rb', line 30

def environment(base = ENV.to_h)
  override = @environment["ZUI_HOST"]
  return base.to_h.dup if override && !override.empty?

  client.environment(base)
end

#executableObject

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
# File 'lib/zui/host.rb', line 13

def executable
  override = @environment["ZUI_HOST"]
  return checked_executable(override) if override && !override.empty?
  return client.executable if client.configured?

  raise ArgumentError, "Zui is not configured for #{platform.id}; run `zui doctor --fix`"
end