Class: Zold::RemoteNode
- Inherits:
-
Object
- Object
- Zold::RemoteNode
- 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:, master:, network: 'test', log: Log::NULL) ⇒ RemoteNode
constructor
A new instance of RemoteNode.
- #master? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(host:, port:, score:, idx:, master:, network: 'test', log: Log::NULL) ⇒ RemoteNode
Returns a new instance of RemoteNode.
44 45 46 47 48 49 50 51 52 |
# File 'lib/zold/remotes.rb', line 44 def initialize(host:, port:, score:, idx:, master:, network: 'test', log: Log::NULL) @host = host @port = port @score = score @idx = idx @master = master @network = network @log = log end |
Instance Method Details
#assert_code(code, response) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zold/remotes.rb', line 66 def assert_code(code, response) msg = response.status_line.strip return if response.status.to_i == code if response.headers && 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
82 83 84 85 |
# File 'lib/zold/remotes.rb', line 82 def assert_score_ownership(score) raise "Masqueraded host #{@host} as #{score.host}: #{score.reduced(4)}" if @host != score.host raise "Masqueraded port #{@port} as #{score.port}: #{score.reduced(4)}" if @port != score.port end |
#assert_score_strength(score) ⇒ Object
87 88 89 90 |
# File 'lib/zold/remotes.rb', line 87 def assert_score_strength(score) return if score.strength >= Score::STRENGTH raise "Score #{score.strength} is too weak (<#{Score::STRENGTH}): #{score.reduced(4)}" end |
#assert_score_value(score, min) ⇒ Object
92 93 94 |
# File 'lib/zold/remotes.rb', line 92 def assert_score_value(score, min) raise "Score #{score.value} is too small (<#{min}): #{score.reduced(4)}" if score.value < min end |
#assert_valid_score(score) ⇒ Object
77 78 79 80 |
# File 'lib/zold/remotes.rb', line 77 def assert_valid_score(score) raise "Invalid score #{score.reduced(4)}" unless score.valid? raise "Expired score (#{Age.new(score.time)}) #{score.reduced(4)}" if score.expired? end |
#http(path = '/') ⇒ Object
54 55 56 |
# File 'lib/zold/remotes.rb', line 54 def http(path = '/') Http.new(uri: "http://#{@host}:#{@port}#{path}", score: @score, network: @network) end |
#master? ⇒ Boolean
58 59 60 |
# File 'lib/zold/remotes.rb', line 58 def master? @master end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/zold/remotes.rb', line 62 def to_s "#{@host}:#{@port}/#{@idx}" end |