lib/zold/remotes.rb in zold-0.1.1 vs lib/zold/remotes.rb in zold-0.1.2
- old
+ new
@@ -27,10 +27,12 @@
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
# License:: MIT
module Zold
# All remotes
class Remotes
+ PORT = 4096
+
def initialize(file)
@file = file
end
def total
@@ -51,27 +53,27 @@
File.join(File.dirname(__FILE__), '../../resources/remotes'),
@file
)
end
- def exists?(host, port = 80)
+ def exists?(host, port = Remotes::PORT)
!load.find { |r| r[:host] == host && r[:port] == port }.nil?
end
- def add(host, port = 80)
+ def add(host, port = Remotes::PORT)
list = load
list << { host: host, port: port, score: 0 }
list.uniq! { |r| "#{r[:host]}:#{r[:port]}" }
save(list)
end
- def remove(host, port = 80)
+ def remove(host, port = Remotes::PORT)
list = load
list.reject! { |r| r[:host] == host && r[:port] == port }
save(list)
end
- def score(host, port = 80)
+ def score(host, port = Remotes::PORT)
load.find { |r| r[:host] == host && r[:port] == port }[:score]
end
def rescore(host, port, score)
list = load