Skip to content

Commit

Permalink
Use zeitwerk to load gem files
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Oct 22, 2024
1 parent fdc0a4b commit b05caec
Show file tree
Hide file tree
Showing 113 changed files with 69 additions and 494 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PATH
faraday-detailed_logger (~> 2.1)
ipaddress (~> 0.8, >= 0.8.3)
openssl (>= 2.0.5)
zeitwerk (~> 2.6)

GEM
remote: https://rubygems.org/
Expand Down
1 change: 1 addition & 0 deletions gemfiles/faraday1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PATH
faraday-detailed_logger (~> 2.1)
ipaddress (~> 0.8, >= 0.8.3)
openssl (>= 2.0.5)
zeitwerk (~> 2.6)

GEM
remote: https://rubygems.org/
Expand Down
1 change: 1 addition & 0 deletions gemfiles/faraday2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PATH
faraday-detailed_logger (~> 2.1)
ipaddress (~> 0.8, >= 0.8.3)
openssl (>= 2.0.5)
zeitwerk (~> 2.6)

GEM
remote: https://rubygems.org/
Expand Down
67 changes: 65 additions & 2 deletions lib/netbox_client_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
require 'dry-configurable'
require 'netbox_client_ruby/error'
require 'netbox_client_ruby/api'
require 'ipaddress'
require 'openssl'

require 'faraday'
require 'faraday/detailed_logger'

if Faraday::VERSION < '2'
begin
require 'faraday_middleware'
rescue LoadError => e
message = <<~MSG
For the current version of Faraday (#{Faraday::VERSION}), "faraday_middleware"
is a required peer dependency of "netbox-client-ruby". Please install
"faraday_middleware" separately OR upgrade to Faraday 2, in which case,
"faraday_middleware" is not needed to work with "netbox-client-ruby".
#{e.message}
MSG
raise NetboxClientRuby::Error, message
end
end

require 'zeitwerk'

# load zeitwerk
Zeitwerk::Loader.for_gem.tap do |loader|
loader.ignore("#{__dir__}/netbox-client-ruby.rb")
loader.collapse("#{__dir__}/netbox_client_ruby/api")
loader.inflector.inflect('dcim' => 'DCIM')
loader.inflector.inflect('ipam' => 'IPAM')
loader.inflector.inflect('rsa_key_pair' => 'RSAKeyPair')
# loader.log!
loader.setup
end

# load gem errors
require_relative 'netbox_client_ruby/error'

module NetboxClientRuby
extend Dry::Configurable
Expand Down Expand Up @@ -29,4 +64,32 @@ module NetboxClientRuby
setting :logger
setting :request_options, default: { open_timeout: 1, timeout: 5 }
end

def self.circuits
NetboxClientRuby::Circuits
end

def self.dcim
NetboxClientRuby::DCIM
end

def self.extras
NetboxClientRuby::Extras
end

def self.ipam
NetboxClientRuby::IPAM
end

def self.secrets
NetboxClientRuby::Secrets
end

def self.tenancy
NetboxClientRuby::Tenancy
end

def self.virtualization
NetboxClientRuby::Virtualization
end
end
38 changes: 0 additions & 38 deletions lib/netbox_client_ruby/api.rb

This file was deleted.

10 changes: 0 additions & 10 deletions lib/netbox_client_ruby/api/circuits.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
require 'netbox_client_ruby/api/circuits/circuit'
require 'netbox_client_ruby/api/circuits/circuits'
require 'netbox_client_ruby/api/circuits/circuit_termination'
require 'netbox_client_ruby/api/circuits/circuit_terminations'
require 'netbox_client_ruby/api/circuits/circuit_type'
require 'netbox_client_ruby/api/circuits/circuit_types'
require 'netbox_client_ruby/api/circuits/provider'
require 'netbox_client_ruby/api/circuits/providers'
require 'netbox_client_ruby/communication'

module NetboxClientRuby
module Circuits
{
Expand Down
5 changes: 0 additions & 5 deletions lib/netbox_client_ruby/api/circuits/circuit.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/circuits/circuit_type'
require 'netbox_client_ruby/api/circuits/provider'
require 'netbox_client_ruby/api/tenancy/tenant'

module NetboxClientRuby
module Circuits
class Circuit
Expand Down
5 changes: 0 additions & 5 deletions lib/netbox_client_ruby/api/circuits/circuit_termination.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/circuits/circuit'
require 'netbox_client_ruby/api/dcim/site'
require 'netbox_client_ruby/api/dcim/interface'

module NetboxClientRuby
module Circuits
class CircuitTermination
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/circuits/circuit_terminations.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/circuits/circuit_termination'

module NetboxClientRuby
module Circuits
class CircuitTerminations
Expand Down
2 changes: 0 additions & 2 deletions lib/netbox_client_ruby/api/circuits/circuit_type.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'netbox_client_ruby/entity'

module NetboxClientRuby
module Circuits
class CircuitType
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/circuits/circuit_types.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/circuits/circuit_type'

module NetboxClientRuby
module Circuits
class CircuitTypes
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/circuits/circuits.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/circuits/circuit'

module NetboxClientRuby
module Circuits
##
Expand Down
2 changes: 0 additions & 2 deletions lib/netbox_client_ruby/api/circuits/provider.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'netbox_client_ruby/entity'

module NetboxClientRuby
module Circuits
class Provider
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/circuits/providers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/circuits/provider'

module NetboxClientRuby
module Circuits
class Providers
Expand Down
44 changes: 0 additions & 44 deletions lib/netbox_client_ruby/api/dcim.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
require 'netbox_client_ruby/api/dcim/console_connection'
require 'netbox_client_ruby/api/dcim/console_connections'
require 'netbox_client_ruby/api/dcim/console_port'
require 'netbox_client_ruby/api/dcim/console_ports'
require 'netbox_client_ruby/api/dcim/console_server_port'
require 'netbox_client_ruby/api/dcim/console_server_ports'
require 'netbox_client_ruby/api/dcim/device'
require 'netbox_client_ruby/api/dcim/devices'
require 'netbox_client_ruby/api/dcim/device_role'
require 'netbox_client_ruby/api/dcim/device_roles'
require 'netbox_client_ruby/api/dcim/device_type'
require 'netbox_client_ruby/api/dcim/device_types'
require 'netbox_client_ruby/api/dcim/interface'
require 'netbox_client_ruby/api/dcim/interface_connection'
require 'netbox_client_ruby/api/dcim/interface_connections'
require 'netbox_client_ruby/api/dcim/interfaces'
require 'netbox_client_ruby/api/dcim/inventory_item'
require 'netbox_client_ruby/api/dcim/inventory_items'
require 'netbox_client_ruby/api/dcim/manufacturer'
require 'netbox_client_ruby/api/dcim/manufacturers'
require 'netbox_client_ruby/api/dcim/platform'
require 'netbox_client_ruby/api/dcim/platforms'
require 'netbox_client_ruby/api/dcim/power_connection'
require 'netbox_client_ruby/api/dcim/power_connections'
require 'netbox_client_ruby/api/dcim/power_outlet'
require 'netbox_client_ruby/api/dcim/power_outlets'
require 'netbox_client_ruby/api/dcim/power_port'
require 'netbox_client_ruby/api/dcim/power_ports'
require 'netbox_client_ruby/api/dcim/rack'
require 'netbox_client_ruby/api/dcim/rack_group'
require 'netbox_client_ruby/api/dcim/rack_groups'
require 'netbox_client_ruby/api/dcim/rack_reservation'
require 'netbox_client_ruby/api/dcim/rack_reservations'
require 'netbox_client_ruby/api/dcim/rack_role'
require 'netbox_client_ruby/api/dcim/rack_roles'
require 'netbox_client_ruby/api/dcim/racks'
require 'netbox_client_ruby/api/dcim/region'
require 'netbox_client_ruby/api/dcim/regions'
require 'netbox_client_ruby/api/dcim/site'
require 'netbox_client_ruby/api/dcim/sites'
require 'netbox_client_ruby/api/dcim/virtual_chassis'
require 'netbox_client_ruby/api/dcim/virtual_chassis_list'
require 'netbox_client_ruby/communication'

module NetboxClientRuby
module DCIM
{
Expand Down
4 changes: 0 additions & 4 deletions lib/netbox_client_ruby/api/dcim/console_connection.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/device'
require 'netbox_client_ruby/api/dcim/console_server_port'

module NetboxClientRuby
module DCIM
class ConsoleConnection
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/console_connections.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/console_connection'

module NetboxClientRuby
module DCIM
class ConsoleConnections
Expand Down
4 changes: 0 additions & 4 deletions lib/netbox_client_ruby/api/dcim/console_port.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/device'
require 'netbox_client_ruby/api/dcim/console_server_port'

module NetboxClientRuby
module DCIM
class ConsolePort
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/console_ports.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/console_port'

module NetboxClientRuby
module DCIM
class ConsolePorts
Expand Down
4 changes: 0 additions & 4 deletions lib/netbox_client_ruby/api/dcim/console_server_port.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/device'
require 'netbox_client_ruby/api/dcim/console_port'

module NetboxClientRuby
module DCIM
class ConsoleServerPort
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/console_server_ports.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/console_server_port'

module NetboxClientRuby
module DCIM
class ConsoleServerPorts
Expand Down
10 changes: 0 additions & 10 deletions lib/netbox_client_ruby/api/dcim/device.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/device_type'
require 'netbox_client_ruby/api/dcim/device_role'
require 'netbox_client_ruby/api/tenancy/tenant'
require 'netbox_client_ruby/api/dcim/platform'
require 'netbox_client_ruby/api/dcim/site'
require 'netbox_client_ruby/api/dcim/rack'
require 'netbox_client_ruby/api/dcim/virtual_chassis'
require 'netbox_client_ruby/api/ipam/ip_address'

module NetboxClientRuby
module DCIM
class Device
Expand Down
2 changes: 0 additions & 2 deletions lib/netbox_client_ruby/api/dcim/device_role.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'netbox_client_ruby/entity'

module NetboxClientRuby
module DCIM
class DeviceRole
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/device_roles.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/device_type'

module NetboxClientRuby
module DCIM
class DeviceRoles
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/device_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/manufacturer'

module NetboxClientRuby
module DCIM
class InterfaceOrdering
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/device_types.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/device_type'

module NetboxClientRuby
module DCIM
class DeviceTypes
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/devices.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/device'

module NetboxClientRuby
module DCIM
class Devices
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/interface.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/device'

module NetboxClientRuby
module DCIM
class Interface
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/interface_connection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/interface'

module NetboxClientRuby
module DCIM
class InterfaceConnection
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/interface_connections.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/interface_connection'

module NetboxClientRuby
module DCIM
class InterfaceConnections
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/interfaces.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/interface'

module NetboxClientRuby
module DCIM
class Interfaces
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/inventory_item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/device'

module NetboxClientRuby
module DCIM
class InventoryItem
Expand Down
3 changes: 0 additions & 3 deletions lib/netbox_client_ruby/api/dcim/inventory_items.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'netbox_client_ruby/entities'
require 'netbox_client_ruby/api/dcim/inventory_item'

module NetboxClientRuby
module DCIM
class InventoryItems
Expand Down
Loading

0 comments on commit b05caec

Please sign in to comment.