Skip to content

Commit 784d3a3

Browse files
Copilotramereth
authored andcommitted
Fix NoMethodError in pg_ident parsing for non-matching lines
Co-authored-by: ramereth <[email protected]> Signed-off-by: Dan Webb <[email protected]>
1 parent f33e7d5 commit 784d3a3

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

.markdownlint-cli2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ config:
77
maximum: 2
88
ignores:
99
- .github/copilot-instructions.md
10+
- .windsurf/**

libraries/ident.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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:)

spec/libraries/ident_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,4 @@
183183
expect(entry1.eql?(entry3)).to be_falsy
184184
end
185185
end
186-
end
186+
end

0 commit comments

Comments
 (0)