Class: Zold::RemoteNode
- Inherits:
-
Object
- Object
- Zold::RemoteNode
- Defined in:
- lib/zold/remotes.rb
Overview
One remote.
Defined Under Namespace
Classes: CantAssert
Instance Attribute Summary collapse
-
#idx ⇒ Object
readonly
Returns the value of attribute idx.
-
#touched ⇒ Object
readonly
Returns the value of attribute touched.
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: Loog::NULL) ⇒ RemoteNode
constructor
A new instance of RemoteNode.
- #master? ⇒ Boolean
- #to_mnemo ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host:, port:, score:, idx:, master:, network: 'test', log: Loog::NULL) ⇒ RemoteNode
Returns a new instance of RemoteNode.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zold/remotes.rb', line 34 def initialize(host:, port:, score:, idx:, master:, network: 'test', log: Loog::NULL) @host = host @port = port @score = score @idx = idx @master = master @network = network @log = log @touched = false end |
Instance Attribute Details
#idx ⇒ Object (readonly)
Returns the value of attribute idx.
32 33 34 |
# File 'lib/zold/remotes.rb', line 32 def idx @idx end |
#touched ⇒ Object (readonly)
Returns the value of attribute touched.
32 33 34 |
# File 'lib/zold/remotes.rb', line 32 def touched @touched end |
Instance Method Details
#assert_code(code, response) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/zold/remotes.rb', line 62 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 CantAssert, "Error ##{response.status} \"#{response.headers['X-Zold-Error']}\" \ at #{response.headers['X-Zold-Path']}" end raise CantAssert, "Unexpected HTTP code #{response.status}, instead of #{code}" if msg.empty? raise CantAssert, "#{msg} (HTTP code #{response.status}, instead of #{code})" end |
#assert_score_ownership(score) ⇒ Object
78 79 80 81 |
# File 'lib/zold/remotes.rb', line 78 def assert_score_ownership(score) raise CantAssert, "Masqueraded host #{@host} as #{score.host}: #{score.reduced(4)}" if @host != score.host raise CantAssert, "Masqueraded port #{@port} as #{score.port}: #{score.reduced(4)}" if @port != score.port end |
#assert_score_strength(score) ⇒ Object
83 84 85 86 87 |
# File 'lib/zold/remotes.rb', line 83 def assert_score_strength(score) return if score.strength >= Score::STRENGTH raise CantAssert, "Score #{score.strength} is too weak (<#{Score::STRENGTH}): #{score.reduced(4)} (use --ignore-score-strength to suppress this check)" end |
#assert_score_value(score, min) ⇒ Object
89 90 91 92 93 |
# File 'lib/zold/remotes.rb', line 89 def assert_score_value(score, min) return if score.value >= min raise CantAssert, "Score #{score.value} is too small (<#{min}): #{score.reduced(4)} (use --ignore-score-size to suppress this check)" end |
#assert_valid_score(score) ⇒ Object
73 74 75 76 |
# File 'lib/zold/remotes.rb', line 73 def assert_valid_score(score) raise CantAssert, "Invalid score #{score.reduced(4)}" unless score.valid? raise CantAssert, "Expired score (#{Age.new(score.time)}) #{score.reduced(4)}" if score.expired? end |
#http(path = '/') ⇒ Object
45 46 47 48 |
# File 'lib/zold/remotes.rb', line 45 def http(path = '/') @touched = true Http.new(uri: "http://#{@host}:#{@port}#{path}", score: @score, network: @network) end |
#master? ⇒ Boolean
50 51 52 |
# File 'lib/zold/remotes.rb', line 50 def master? @master end |
#to_mnemo ⇒ Object
58 59 60 |
# File 'lib/zold/remotes.rb', line 58 def to_mnemo "#{@host}:#{@port}" end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/zold/remotes.rb', line 54 def to_s "#{@host}:#{@port}/#{@idx}" end |