Module: NetboxClientRuby::Entities
- Includes:
- Enumerable, Communication
- Included in:
- DCIM::DeviceRoles, DCIM::DeviceTypes, DCIM::Devices, DCIM::Interfaces, DCIM::InventoryItems, DCIM::Manufacturers, DCIM::Platforms, DCIM::PowerOutlets, DCIM::PowerPorts, DCIM::RackGroups, DCIM::Racks, DCIM::Regions, DCIM::Sites, IPAM::Aggregates, IPAM::IpAddresses, IPAM::Prefixes, IPAM::Rirs, IPAM::Roles, IPAM::VlanGroups, IPAM::Vlans, IPAM::Vrfs, Secrets::SecretRoles, Secrets::Secrets, Tenancy::TenantGroups, Tenancy::Tenants
- Defined in:
- lib/netbox_client_ruby/entities.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary
collapse
Instance Method Summary
collapse
#connection, #hash_to_object, #response
Class Method Details
.included(other_klass) ⇒ Object
9
10
11
|
# File 'lib/netbox_client_ruby/entities.rb', line 9
def self.included(other_klass)
other_klass.extend ClassMethods
end
|
Instance Method Details
#[](index) ⇒ Object
118
119
120
121
122
|
# File 'lib/netbox_client_ruby/entities.rb', line 118
def [](index)
return nil if length <= index
as_entity raw_data_array[index]
end
|
#all ⇒ Object
86
87
88
89
90
|
# File 'lib/netbox_client_ruby/entities.rb', line 86
def all
@instance_limit = NetboxClientRuby.config.netbox..max_limit
reset
self
end
|
#each ⇒ Object
124
125
126
|
# File 'lib/netbox_client_ruby/entities.rb', line 124
def each
raw_data_array.each { |raw_entity| yield as_entity(raw_entity) }
end
|
#filter(filter) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/netbox_client_ruby/entities.rb', line 78
def filter(filter)
raise ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash
@filter = filter
reset
self
end
|
#length ⇒ Object
Also known as:
size
The number of entities that have been fetched
130
131
132
|
# File 'lib/netbox_client_ruby/entities.rb', line 130
def length
raw_data_array.length
end
|
#limit(limit) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/netbox_client_ruby/entities.rb', line 92
def limit(limit)
self.class.check_limit limit unless limit.nil?
@instance_limit = limit
reset
self
end
|
#offset(offset) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/netbox_client_ruby/entities.rb', line 100
def offset(offset)
raise ArgumentError, "The offset '#{offset}' is not numeric." unless offset.is_a? Numeric
raise ArgumentError, "The offset '#{offset}' must not be negative." if offset.negative?
@offset = offset
reset
self
end
|
#page(page) ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'lib/netbox_client_ruby/entities.rb', line 109
def page(page)
raise ArgumentError, "The offset '#{page}' is not numeric but has to be." unless page.is_a? Numeric
raise ArgumentError, "The offset '#{page}' must be integer but isn't." unless page.integer?
raise ArgumentError, "The offset '#{page}' must not be negative but is." if page.negative?
limit = @instance_limit || self.class.limit
offset(limit * page)
end
|
#raw_data! ⇒ Object
145
146
147
|
# File 'lib/netbox_client_ruby/entities.rb', line 145
def raw_data!
data
end
|
#reload ⇒ Object
Also known as:
get!
140
141
142
143
|
# File 'lib/netbox_client_ruby/entities.rb', line 140
def reload
@data = get
self
end
|
#total ⇒ Object
Also known as:
count
The total number of available entities for that query
136
137
138
|
# File 'lib/netbox_client_ruby/entities.rb', line 136
def total
data[self.class.count_key]
end
|