Module: NetboxClientRuby::Entities
- Includes:
- Enumerable, Communication
- Included in:
- Circuits::CircuitTerminations, Circuits::CircuitTypes, Circuits::Circuits, Circuits::Providers, DCIM::ConsoleConnections, DCIM::ConsolePorts, DCIM::ConsoleServerPorts, DCIM::DeviceRoles, DCIM::DeviceTypes, DCIM::Devices, DCIM::InterfaceConnections, DCIM::Interfaces, DCIM::InventoryItems, DCIM::MacAddresses, DCIM::Manufacturers, DCIM::Platforms, DCIM::PowerConnections, DCIM::PowerOutlets, DCIM::PowerPorts, DCIM::RackGroups, DCIM::RackReservations, DCIM::RackRoles, DCIM::Racks, DCIM::Regions, DCIM::Sites, DCIM::VirtualChassisList, NetboxClientRuby::Extras::ConfigContexts, NetboxClientRuby::Extras::JournalEntries, NetboxClientRuby::Extras::Tags, IPAM::Aggregates, IPAM::IpAddresses, IPAM::IpRanges, IPAM::Prefixes, IPAM::Rirs, IPAM::Roles, IPAM::Services, IPAM::VlanGroups, IPAM::Vlans, IPAM::Vrfs, Secrets::SecretRoles, Secrets::Secrets, Tenancy::ContactGroups, Tenancy::Contacts, Tenancy::TenantGroups, Tenancy::Tenants, Virtualization::ClusterGroups, Virtualization::ClusterTypes, Virtualization::Clusters, Virtualization::Interfaces, Virtualization::VirtualMachines
- Defined in:
- lib/netbox_client_ruby/entities.rb
Overview
rubocop:disable Metrics/ModuleLength
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
- #all ⇒ Object
- #each ⇒ Object
- #filter(filter) ⇒ Object
-
#find_by(attributes) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
-
#length ⇒ Object
(also: #size)
The number of entities that have been fetched.
- #limit(limit) ⇒ Object
- #offset(offset) ⇒ Object
- #page(page) ⇒ Object
- #raw_data! ⇒ Object
- #reload ⇒ Object (also: #get!)
-
#total ⇒ Object
(also: #count)
The total number of available entities for that query.
Methods included from Communication
Class Method Details
.included(other_klass) ⇒ Object
8 9 10 |
# File 'lib/netbox_client_ruby/entities.rb', line 8 def self.included(other_klass) other_klass.extend ClassMethods end |
Instance Method Details
#[](index) ⇒ Object
135 136 137 138 139 |
# File 'lib/netbox_client_ruby/entities.rb', line 135 def [](index) return nil if length <= index as_entity raw_data_array[index] end |
#all ⇒ Object
103 104 105 106 107 |
# File 'lib/netbox_client_ruby/entities.rb', line 103 def all @instance_limit = NetboxClientRuby.config.netbox.pagination.max_limit reset self end |
#each ⇒ Object
141 142 143 |
# File 'lib/netbox_client_ruby/entities.rb', line 141 def each raw_data_array.each { |raw_entity| yield as_entity(raw_entity) } end |
#filter(filter) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/netbox_client_ruby/entities.rb', line 95 def filter(filter) raise ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash @filter = filter reset self end |
#find_by(attributes) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/netbox_client_ruby/entities.rb', line 77 def find_by(attributes) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength raise ArgumentError, '"attributes" expects a hash' unless attributes.is_a? Hash filter(attributes).find do |netbox_object| attributes.all? do |filter_key, filter_value| if filter_key.to_s.start_with?('cf_') custom_field = filter_key.to_s.sub('cf_', '') netbox_object.custom_fields[custom_field].to_s == filter_value.to_s elsif netbox_object.respond_to?(filter_key) netbox_object.public_send(filter_key).to_s == filter_value.to_s else false end end end end |
#length ⇒ Object Also known as: size
The number of entities that have been fetched
147 148 149 |
# File 'lib/netbox_client_ruby/entities.rb', line 147 def length raw_data_array.length end |
#limit(limit) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/netbox_client_ruby/entities.rb', line 109 def limit(limit) self.class.check_limit limit unless limit.nil? @instance_limit = limit reset self end |
#offset(offset) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/netbox_client_ruby/entities.rb', line 117 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
126 127 128 129 130 131 132 133 |
# File 'lib/netbox_client_ruby/entities.rb', line 126 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
162 163 164 |
# File 'lib/netbox_client_ruby/entities.rb', line 162 def raw_data! data end |
#reload ⇒ Object Also known as: get!
157 158 159 160 |
# File 'lib/netbox_client_ruby/entities.rb', line 157 def reload @data = get self end |
#total ⇒ Object Also known as: count
The total number of available entities for that query
153 154 155 |
# File 'lib/netbox_client_ruby/entities.rb', line 153 def total data[self.class.count_key] end |