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

Switched to Zeitwerk as autoloader. #27

Merged
merged 1 commit into from
Jan 11, 2025
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
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ concurrency:

jobs:
test:
name: 'Test the gem (Ruby ${{ matrix.ruby }})'
name: 'Test the gem (Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }})'
runs-on: ubuntu-22.04
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0']
rails: ['6.1', '7.1']
env:
BUNDLE_GEMFILE: 'gemfiles/rails_${{ matrix.rails }}.gemfile'
steps:
- uses: actions/checkout@v4

Expand Down
9 changes: 9 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

appraise 'rails-6.1' do
gem 'activesupport', '~> 6.1.0'
end

appraise 'rails-7.1' do
gem 'activesupport', '~> 7.1.0'
end
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### next

* TODO: Replace this bullet point with an actual description of a change.
* Switched to Zeitwerk as autoloader (#27)

### 1.3.0 (3 January 2025)

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source 'https://rubygems.org'
gemspec

# Development dependencies
gem 'appraisal', '~> 2.4'
gem 'bundler', '~> 2.3'
gem 'countless', '~> 1.1'
gem 'guard-rspec', '~> 4.7'
Expand Down
33 changes: 30 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ BASH_RUN_SHELL_FLAGS ?=

# Directories
VENDOR_DIR ?= vendor/bundle
GEMFILES_DIR ?= gemfiles

# Host binaries
AWK ?= awk
BASH ?= bash
COMPOSE ?= docker-compose
CP ?= cp
DOCKER ?= docker
EXPORT ?= export
FIND ?= find
GREP ?= grep
HEAD ?= head
ID ?= id
MKDIR ?= mkdir
RM ?= rm
SORT ?= sort
TEST ?= test
XARGS ?= xargs

# Container binaries
APPRAISAL ?= appraisal
BUNDLE ?= bundle
GEM ?= gem
GUARD ?= guard
Expand All @@ -37,6 +43,12 @@ RUBOCOP ?= rubocop
YARD ?= yard
RUBY_VERSION := ruby-version

# Files
GEMFILES ?= $(subst _,-,$(patsubst $(GEMFILES_DIR)/%.gemfile,%,\
$(wildcard $(GEMFILES_DIR)/*.gemfile)))
TEST_GEMFILES := $(GEMFILES:%=test-%)
WATCH_GEMFILES := $(GEMFILES:%=watch-%)

# Define a generic shell run wrapper
# $1 - The command to run
ifeq ($(MAKE_ENV),docker)
Expand All @@ -57,6 +69,7 @@ all:
# Billomat
#
# install Install the dependencies
# update Update the local Gemset dependencies
# clean Clean the dependencies
#
# test Run the whole test suite
Expand All @@ -78,16 +91,23 @@ install:
# Install the dependencies
@$(MKDIR) -p $(VENDOR_DIR)
@$(call run-shell,$(BUNDLE) check || $(BUNDLE) install --path $(VENDOR_DIR))
@$(call run-shell,$(BUNDLE) exec $(APPRAISAL) install)

update:
# Install the dependencies
@$(MKDIR) -p $(VENDOR_DIR)
@$(call run-shell,$(BUNDLE) update)
@$(call run-shell,$(BUNDLE) exec $(APPRAISAL) update)

watch: install .interactive
# Watch for code changes and rerun the test suite
@$(call run-shell,$(BUNDLE) exec $(GUARD))

$(WATCH_GEMFILES): GEMFILE=$(@:watch-%=%)
$(WATCH_GEMFILES):
# Watch for code changes and rerun the test suite ($(GEMFILE))
@$(call run-shell,$(BUNDLE) exec $(APPRAISAL) $(GEMFILE) $(GUARD))

test: \
test-specs \
test-style
Expand All @@ -96,6 +116,11 @@ test-specs:
# Run the whole test suite
@$(call run-shell,$(BUNDLE) exec $(RAKE) stats spec)

$(TEST_GEMFILES): GEMFILE=$(@:test-%=%)
$(TEST_GEMFILES):
# Run the whole test suite ($(GEMFILE))
@$(call run-shell,$(BUNDLE) exec $(APPRAISAL) $(GEMFILE) $(RSPEC))

test-style: \
test-style-ruby

Expand All @@ -107,7 +132,9 @@ test-style-ruby:
clean:
# Clean the dependencies
@$(RM) -rf $(VENDOR_DIR)
@$(RM) -rf $(VENDOR_DIR)/Gemfile.lock
@$(RM) -rf Gemfile.lock
@$(RM) -rf $(GEMFILES_DIR)/vendor
@$(RM) -rf $(GEMFILES_DIR)/*.lock
@$(RM) -rf .bundle .yardoc coverage pkg Gemfile.lock doc/api \
.rspec_status

Expand All @@ -127,11 +154,11 @@ endif

distclean: clean clean-containers clean-images

shell:
shell: install
# Run an interactive shell on the container
@$(call run-shell,$(BASH) -i)

shell-irb:
shell-irb: install
# Run an interactive IRB shell on the container
@$(call run-shell,bin/console)

Expand Down
2 changes: 2 additions & 0 deletions billomat.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.7'

spec.add_dependency 'rest-client', '~> 2.1'
spec.add_dependency 'activesupport', '>= 6.1'
spec.add_dependency 'zeitwerk', '~> 2.6'
end
20 changes: 20 additions & 0 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal", "~> 2.4"
gem "bundler", "~> 2.3"
gem "countless", "~> 1.1"
gem "guard-rspec", "~> 4.7"
gem "irb", "~> 1.2"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.12"
gem "rubocop", "~> 1.28"
gem "rubocop-rails", "~> 2.14"
gem "rubocop-rspec", "~> 2.10"
gem "simplecov", ">= 0.22"
gem "yard", ">= 0.9.28"
gem "yard-activesupport-concern", ">= 0.0.1"
gem "activesupport", "~> 6.1.0"

gemspec path: "../"
20 changes: 20 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal", "~> 2.4"
gem "bundler", "~> 2.3"
gem "countless", "~> 1.1"
gem "guard-rspec", "~> 4.7"
gem "irb", "~> 1.2"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.12"
gem "rubocop", "~> 1.28"
gem "rubocop-rails", "~> 2.14"
gem "rubocop-rspec", "~> 2.10"
gem "simplecov", ">= 0.22"
gem "yard", ">= 0.9.28"
gem "yard-activesupport-concern", ">= 0.0.1"
gem "activesupport", "~> 7.1.0"

gemspec path: "../"
24 changes: 18 additions & 6 deletions lib/billomat.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# frozen_string_literal: true

require 'billomat/version'
require 'billomat/configuration'
require 'billomat/models'
require 'billomat/actions'
require 'billomat/search'
require 'billomat/gateway'
require 'zeitwerk'
require 'active_support'
require 'rest-client'
require 'json'
require 'ostruct'
require 'uri'

# An wrapper for the Billomat API.
module Billomat
# Configure the relative gem code base location
root_path = Pathname.new("#{__dir__}/billomat")

# Setup a Zeitwerk autoloader instance and configure it
loader = Zeitwerk::Loader.for_gem

# Finish the auto loader configuration
loader.setup

# Make sure to eager load all SDK constants
loader.eager_load

class << self
attr_writer :configuration

Expand Down
13 changes: 0 additions & 13 deletions lib/billomat/actions.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/billomat/gateway.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require 'rest-client'
require 'json'

module Billomat
# Raised if something goes wrong during an API call.
class GatewayError < StandardError
Expand Down
18 changes: 0 additions & 18 deletions lib/billomat/models.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/billomat/models/base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'ostruct'

module Billomat
module Models
# This class is the base for all other models (resources).
Expand Down
2 changes: 0 additions & 2 deletions lib/billomat/search.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'uri'

module Billomat
# This class provides the possibility to query the resources.
class Search
Expand Down
1 change: 1 addition & 0 deletions spec/support/suite_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
puts <<DESC
-------------- Versions --------------
Ruby: #{"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"}
Active Support: #{ActiveSupport.version}
--------------------------------------
DESC
puts