Class: Zold::Remotes::Remote

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/zold/remotes.rb

Overview

One remote.

Instance Method Summary collapse

Instance Method Details

#assert_code(code, response) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/zold/remotes.rb', line 82

def assert_code(code, response)
  msg = response.message.strip
  return if response.code.to_i == code
  raise "#{response.code}/#{response.header['X-Zold-Error']}" if response.header['X-Zold-Error']
  raise "Unexpected HTTP code #{response.code}, instead of #{code}" if msg.empty?
  raise "#{msg} (HTTP code #{response.code}, instead of #{code})"
end

#assert_score_ownership(score) ⇒ Object



95
96
97
98
# File 'lib/zold/remotes.rb', line 95

def assert_score_ownership(score)
  raise "Masqueraded host #{host} as #{score.host}: #{score}" if host != score.host
  raise "Masqueraded port #{port} as #{score.port}: #{score}" if port != score.port
end

#assert_score_strength(score) ⇒ Object



100
101
102
# File 'lib/zold/remotes.rb', line 100

def assert_score_strength(score)
  raise "Score #{score.strength} is too weak (<#{Score::STRENGTH}): #{score}" if score.strength < Score::STRENGTH
end

#assert_score_value(score, min) ⇒ Object



104
105
106
# File 'lib/zold/remotes.rb', line 104

def assert_score_value(score, min)
  raise "Score is too small (<#{min}): #{score}" if score.value < min
end

#assert_valid_score(score) ⇒ Object



90
91
92
93
# File 'lib/zold/remotes.rb', line 90

def assert_valid_score(score)
  raise "Invalid score #{score}" unless score.valid?
  raise "Expired score #{score}" if score.expired?
end

#http(path = '/') ⇒ Object



74
75
76
# File 'lib/zold/remotes.rb', line 74

def http(path = '/')
  Http.new(uri: "http://#{host}:#{port}#{path}", score: score, network: network)
end

#to_sObject



78
79
80
# File 'lib/zold/remotes.rb', line 78

def to_s
  "#{host}:#{port}/#{idx}"
end