Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use zeitwerk to load gem files #87

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
67 changes: 65 additions & 2 deletions lib/netbox_client_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
# frozen_string_literal: true

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 @@ -31,4 +66,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
40 changes: 0 additions & 40 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,15 +1,5 @@
# frozen_string_literal: true

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,10 +1,5 @@
# frozen_string_literal: true

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,10 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,7 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,7 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,49 +1,5 @@
# frozen_string_literal: true

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,9 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,9 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,9 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,15 +1,5 @@
# frozen_string_literal: true

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,7 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

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,8 +1,5 @@
# frozen_string_literal: true

require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/dcim/interface'

module NetboxClientRuby
module DCIM
class InterfaceConnection
Expand Down
Loading