@@ -77,7 +77,7 @@ def initialize
7777 end
7878
7979 def add ( entry )
80- raise unless entry . is_a? ( PgIdentFileEntry )
80+ raise ArgumentError , "Expected PgIdentFileEntry, got #{ entry . class } " unless entry . is_a? ( PgIdentFileEntry )
8181
8282 return false if include? ( entry )
8383
@@ -107,11 +107,11 @@ def entry(map_name, system_username = nil, database_username = nil)
107107 end
108108
109109 def entry? ( map_name )
110- ! @entries . none ? { |e | e . map_name . eql? ( map_name ) }
110+ @entries . any ? { |e | e . map_name . eql? ( map_name ) }
111111 end
112112
113113 def include? ( entry )
114- raise unless entry . is_a? ( PgIdentFileEntry )
114+ raise ArgumentError , "Expected PgIdentFileEntry, got #{ entry . class } " unless entry . is_a? ( PgIdentFileEntry )
115115
116116 @entries . any? { |e | e . eql? ( entry ) }
117117 end
@@ -131,7 +131,7 @@ def read!(file = 'pg_ident.conf', sort: true)
131131 end
132132
133133 def remove ( entry )
134- raise unless entry . is_a? ( PgIdentFileEntry ) || entry . is_a? ( String )
134+ raise ArgumentError , "Expected PgIdentFileEntry or String, got #{ entry . class } " unless entry . is_a? ( PgIdentFileEntry ) || entry . is_a? ( String )
135135
136136 case entry
137137 when PgIdentFileEntry
@@ -191,8 +191,9 @@ class PgIdentFileEntry
191191 comment : 0 ,
192192 } . freeze
193193 ENTRY_FIELDS = ENTRY_FIELD_FORMAT . keys . dup . freeze
194+ COMPOSITE_KEY_FIELDS = %i( map_name system_username database_username ) . freeze
194195
195- private_constant :ENTRY_FIELD_FORMAT , :ENTRY_FIELDS
196+ private_constant :ENTRY_FIELD_FORMAT , :ENTRY_FIELDS , :COMPOSITE_KEY_FIELDS
196197
197198 def initialize ( map_name :, system_username :, database_username :, comment : nil )
198199 @map_name = map_name
@@ -215,9 +216,7 @@ def to_s
215216 def eql? ( other )
216217 return false unless self . class . eql? ( other . class )
217218
218- return true if %i( map_name system_username database_username ) . all? { |field | send ( field ) . eql? ( entry . send ( field ) ) }
219-
220- false
219+ COMPOSITE_KEY_FIELDS . all? { |field | send ( field ) . eql? ( other . send ( field ) ) }
221220 end
222221
223222 def update ( system_username :, database_username :, comment :)
0 commit comments