Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail

bundle exec rake spec
10 changes: 6 additions & 4 deletions lib/netbox_client_ruby/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ def find_by(attributes)
custom_field = filter_key.to_s.sub('cf_', '')

netbox_object.custom_fields[custom_field].to_s == filter_value.to_s
else
if netbox_object.respond_to?(filter_key)
netbox_object.public_send(filter_key).to_s == filter_value.to_s
elsif netbox_object.respond_to?(filter_key)
if netbox_object.public_send(filter_key).is_a?(IPAddress)
netbox_object.public_send(filter_key).to_string == filter_value.to_s
else
false
netbox_object.public_send(filter_key).to_s == filter_value.to_s
end
else
false
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/netbox_client_ruby/api/ipam/ip_addresses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@
end
end
end

describe '#find_by' do
it 'should return a match with to_string' do
expect(subject.find_by({ address: '10.0.0.1/8' })['address']).to eq('10.0.0.1/8')
end
end
end