Skip to content

Commit

Permalink
Add missing properties to NtpServer
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 18, 2020
1 parent 2fb3659 commit 7006851
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/lib/y2network/ntp_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class NtpServer
attr_reader :country
# @return [String,nil] Server's location
attr_reader :location
# @return [String,nil] Location details
attr_reader :exact_location
# @return [String,nil] Stratum level
attr_reader :stratum
# @return [String,nil] Synchronization mechanism
attr_reader :synchronization
# @return [String,nil] Access policy
attr_reader :access_policy

class << self
DEFAULT_SERVERS = 4
Expand Down Expand Up @@ -62,29 +70,49 @@ def default_servers(products = nil)
# @param path [String] File path
# @return [Array<NtpServer>] Array containing all the servers
def load_from_file(path)
YAML.load_file(path).map do |server|
new(server["address"], country: server["country"], location: server["location"])
YAML.load_file(path).map do |srv|
new(
srv["address"], country: srv["country"], location: srv["location"],
exact_location: srv["exact_location"], stratum: srv["stratum"],
synchronization: srv["synchronization"], access_policy: srv["access_policy"]
)
end
end
end

# Constructor
#
# @param hostname [String] Server's hostname
# @param country [String] Country code (e.g., "DE")
# @param location [String] Server's location
def initialize(hostname, country: nil, location: nil)
# @param hostname [String] Hostname
# @param country [String] Country code (e.g., "DE")
# @param location [String] Location
# @param exact_location [String] Location details
# @param stratum [String] Stratum level
# @param synchronization [String] Synchronization mechanism
# @param access_policy [String] Access policy
def initialize(hostname, country: nil, location: nil, exact_location: nil, stratum: nil,
synchronization: nil, access_policy: nil)
@hostname = hostname
@country = country
@location = location
@exact_location = exact_location
@stratum = stratum
@synchronization = synchronization
@access_policy = access_policy
end

EQUALITY_METHS = [
:hostname, :country, :location, :exact_location, :stratum, :synchronization, :access_policy
].freeze
private_constant :EQUALITY_METHS

# Determines when two servers are the same
#
# @param other [NtpServer] Object to compare with
# @return [Boolean] true if both objects contain the same information; false otherwise
def ==(other)
hostname == other.hostname && country == other.country && location == other.location
EQUALITY_METHS.all? do |attr|
public_send(attr) == other.public_send(attr)
end
end

alias_method :eql?, :==
Expand Down
1 change: 1 addition & 0 deletions test/data/ntp_servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
location: Czech Republic
stratum: '2'
synchronization: NTP V4 secondary (stratum 2), PC/FreeBSD
coordinates: 49:80N, 15:47W

0 comments on commit 7006851

Please sign in to comment.