Class: Zold::Remotes::Remote
- Inherits:
-
Object
- Object
- Zold::Remotes::Remote
- Defined in:
- lib/zold/remotes.rb
Overview
One remote.
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
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, log: Log::Quiet.new) ⇒ Remote
constructor
A new instance of Remote.
- #to_s ⇒ Object
Constructor Details
#initialize(host, port, score, log: Log::Quiet.new) ⇒ Remote
Returns a new instance of Remote.
54 55 56 57 58 59 60 61 |
# File 'lib/zold/remotes.rb', line 54 def initialize(host, port, score, log: Log::Quiet.new) @host = host raise 'Post must be Integer' unless port.is_a?(Integer) @port = port raise 'Score must be of type Score' unless score.is_a?(Score) @score = score @log = log end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
53 54 55 |
# File 'lib/zold/remotes.rb', line 53 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
53 54 55 |
# File 'lib/zold/remotes.rb', line 53 def port @port end |
Instance Method Details
#assert_code(code, response) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/zold/remotes.rb', line 71 def assert_code(code, response) msg = response..strip return if response.code.to_i == code @log.debug("#{response.code} \"#{response.message}\" at \"#{response.body}\"") 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
84 85 86 87 |
# File 'lib/zold/remotes.rb', line 84 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
89 90 91 |
# File 'lib/zold/remotes.rb', line 89 def assert_score_strength(score) raise "Score is too weak #{score.strength}: #{score}" if score.strength < Score::STRENGTH end |
#assert_score_value(score, min) ⇒ Object
93 94 95 |
# File 'lib/zold/remotes.rb', line 93 def assert_score_value(score, min) raise "Score is too small (<#{min}): #{score}" if score.value < min end |
#assert_valid_score(score) ⇒ Object
79 80 81 82 |
# File 'lib/zold/remotes.rb', line 79 def assert_valid_score(score) raise "Invalid score #{score}" unless score.valid? raise "Expired score #{score}" if score.expired? end |
#http(path = '/') ⇒ Object
63 64 65 |
# File 'lib/zold/remotes.rb', line 63 def http(path = '/') Http.new("http://#{@host}:#{@port}#{path}", @score) end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/zold/remotes.rb', line 67 def to_s "#{@host}:#{@port}" end |