Class: Zold::Remotes::Remote
- Inherits:
-
Object
- Object
- 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
-
#initialize(host:, port:, score:, idx:, network: 'test', log: Log::NULL) ⇒ Remote
constructor
A new instance of Remote.
- #to_s ⇒ Object
Constructor Details
#initialize(host:, port:, score:, idx:, network: 'test', log: Log::NULL) ⇒ Remote
Returns a new instance of Remote.
77 78 79 80 81 82 83 84 |
# File 'lib/zold/remotes.rb', line 77 def initialize(host:, port:, score:, idx:, network: 'test', log: Log::NULL) @host = host @port = port @score = score @idx = idx @network = network @log = log end |
Instance Method Details
#assert_code(code, response) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/zold/remotes.rb', line 94 def assert_code(code, response) msg = response.status_line.strip return if response.status.to_i == code if response.headers['X-Zold-Error'] raise "Error ##{response.status} \"#{response.headers['X-Zold-Error']}\" at #{response.headers['X-Zold-Path']}" end raise "Unexpected HTTP code #{response.status}, instead of #{code}" if msg.empty? raise "#{msg} (HTTP code #{response.status}, instead of #{code})" end |
#assert_score_ownership(score) ⇒ Object
110 111 112 113 |
# File 'lib/zold/remotes.rb', line 110 def assert_score_ownership(score) raise "Masqueraded host #{@host} as #{score.host}: #{score.reduce(4)}" if @host != score.host raise "Masqueraded port #{@port} as #{score.port}: #{score.reduce(4)}" if @port != score.port end |
#assert_score_strength(score) ⇒ Object
115 116 117 118 |
# File 'lib/zold/remotes.rb', line 115 def assert_score_strength(score) return if score.strength >= Score::STRENGTH raise "Score #{score.strength} is too weak (<#{Score::STRENGTH}): #{score.reduce(4)}" end |
#assert_score_value(score, min) ⇒ Object
120 121 122 |
# File 'lib/zold/remotes.rb', line 120 def assert_score_value(score, min) raise "Score #{score.value} is too small (<#{min}): #{score.reduce(4)}" if score.value < min end |
#assert_valid_score(score) ⇒ Object
105 106 107 108 |
# File 'lib/zold/remotes.rb', line 105 def assert_valid_score(score) raise "Invalid score #{score}" unless score.valid? raise "Expired score (#{Age.new(score.time)}) #{score.reduce(4)}" if score.expired? end |
#http(path = '/') ⇒ Object
86 87 88 |
# File 'lib/zold/remotes.rb', line 86 def http(path = '/') Http.new(uri: "http://#{@host}:#{@port}#{path}", score: @score, network: @network) end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/zold/remotes.rb', line 90 def to_s "#{@host}:#{@port}/#{@idx}" end |