Class: Zold::Remotes::Remote
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Zold::Remotes::Remote
- Defined in:
- lib/zold/remotes.rb
Overview
One remote.
Instance Method Summary collapse
- #assert_code(code, response) ⇒ Object
- #assert_score_ownership(score) ⇒ Object
- #assert_score_strength(score) ⇒ Object
- #assert_score_value(score, min) ⇒ Object
- #assert_valid_score(score) ⇒ Object
- #http(path = '/') ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#assert_code(code, response) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/zold/remotes.rb', line 95 def assert_code(code, response) msg = response..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
108 109 110 111 |
# File 'lib/zold/remotes.rb', line 108 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
113 114 115 |
# File 'lib/zold/remotes.rb', line 113 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
117 118 119 |
# File 'lib/zold/remotes.rb', line 117 def assert_score_value(score, min) raise "Score #{score.value} is too small (<#{min}): #{score}" if score.value < min end |
#assert_valid_score(score) ⇒ Object
103 104 105 106 |
# File 'lib/zold/remotes.rb', line 103 def assert_valid_score(score) raise "Invalid score #{score}" unless score.valid? raise "Expired score (#{Age.new(score.time)}) #{score}" if score.expired? end |
#http(path = '/') ⇒ Object
87 88 89 |
# File 'lib/zold/remotes.rb', line 87 def http(path = '/') Http.new(uri: "http://#{host}:#{port}#{path}", score: score, network: network) end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/zold/remotes.rb', line 91 def to_s "#{host}:#{port}/#{idx}" end |