Skip to content

Commit 071ac70

Browse files
authored
Merge pull request #16 from ninech/enumerable
Enumerable
2 parents 2f29662 + 5abf4d8 commit 071ac70

27 files changed

+78
-58
lines changed

lib/netbox_client_ruby/entities.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
module NetboxClientRuby
55
module Entities
66
include NetboxClientRuby::Communication
7+
include Enumerable
78

89
def self.included(other_klass)
910
other_klass.extend ClassMethods
@@ -120,8 +121,8 @@ def [](index)
120121
as_entity raw_data_array[index]
121122
end
122123

123-
def as_array
124-
raw_data_array.map { |raw_entity| as_entity raw_entity }
124+
def each
125+
raw_data_array.each { |raw_entity| yield as_entity(raw_entity) }
125126
end
126127

127128
##

spec/netbox_client_ruby/api/dcim/device_roles_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

spec/netbox_client_ruby/api/dcim/device_types_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

spec/netbox_client_ruby/api/dcim/devices_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

spec/netbox_client_ruby/api/dcim/interfaces_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

spec/netbox_client_ruby/api/dcim/inventory_items_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

spec/netbox_client_ruby/api/dcim/manufacturers_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242

4343
describe '#as_array' do
4444
it 'return the correct amount' do
45-
expect(subject.as_array.length).to be 2
45+
expect(subject.to_a.length).to be 2
4646
end
4747

4848
it 'returns Site instances' do
49-
subject.as_array.each do |element|
49+
subject.to_a.each do |element|
5050
expect(element).to be_a NetboxClientRuby::DCIM::Region
5151
end
5252
end

spec/netbox_client_ruby/api/dcim/platforms_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

spec/netbox_client_ruby/api/dcim/power_outlets_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

spec/netbox_client_ruby/api/dcim/power_ports_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545

4646
describe '#as_array' do
4747
it 'return the correct amount' do
48-
expect(subject.as_array.length).to be expected_length
48+
expect(subject.to_a.length).to be expected_length
4949
end
5050

5151
it 'returns Site instances' do
52-
subject.as_array.each do |element|
52+
subject.to_a.each do |element|
5353
expect(element).to be_a singular_type
5454
end
5555
end

0 commit comments

Comments
 (0)