Class: Canopus::Workspace::Trust

Inherits:
Object
  • Object
show all
Defined in:
lib/canopus/workspace/trust.rb,
sig/trust.rbs

Instance Method Summary collapse

Constructor Details

#initialize(root, state_path: nil) ⇒ Trust

Returns a new instance of Trust.

Parameters:

  • root (String)
  • state_path: (String, nil) (defaults to: nil)


10
11
12
13
14
15
# File 'lib/canopus/workspace/trust.rb', line 10

def initialize(root, state_path: nil)
  @root = File.realpath(root)
  @state_path = state_path || File.join(ENV["XDG_STATE_HOME"] || File.expand_path("~/.local/state"), "canopus", "trust.json")
  @key = Digest::SHA256.hexdigest(@root)
  @states = load_states
end

Instance Method Details

#status ⇒ :trusted, :untrusted

Returns:

  • (:trusted, :untrusted)


18
# File 'lib/canopus/workspace/trust.rb', line 18

def status = trusted? ? :trusted : :untrusted

#trust! ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/canopus/workspace/trust.rb', line 20

def trust!
  update(true)
end

#trusted? ⇒ Boolean

Returns:

  • (Boolean)


17
# File 'lib/canopus/workspace/trust.rb', line 17

def trusted? = @states[@key] == true

#untrust! ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/canopus/workspace/trust.rb', line 24

def untrust!
  update(false)
end