diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bca2819..e38f016 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..79b09c2 --- /dev/null +++ b/Appraisals @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0935412..bbf2fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Gemfile b/Gemfile index 47ac1a5..56a3c17 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Makefile b/Makefile index 9d8976d..7135b7e 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ BASH_RUN_SHELL_FLAGS ?= # Directories VENDOR_DIR ?= vendor/bundle +GEMFILES_DIR ?= gemfiles # Host binaries AWK ?= awk @@ -20,14 +21,19 @@ 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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/billomat.gemspec b/billomat.gemspec index 9ad204b..9de86eb 100644 --- a/billomat.gemspec +++ b/billomat.gemspec @@ -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 diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 0000000..db16eeb --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -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: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..4067071 --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -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: "../" diff --git a/lib/billomat.rb b/lib/billomat.rb index d14b746..48050dc 100644 --- a/lib/billomat.rb +++ b/lib/billomat.rb @@ -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 diff --git a/lib/billomat/actions.rb b/lib/billomat/actions.rb deleted file mode 100644 index 772dd70..0000000 --- a/lib/billomat/actions.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require 'billomat/actions/complete' -require 'billomat/actions/email' -require 'billomat/actions/pdf' -require 'billomat/actions/cancel' -require 'billomat/actions/uncancel' - -module Billomat - # Actions are API calls that do not directly represent a resource. - # They are mostly non-RESTful actions that are called on a resources. - module Actions; end -end diff --git a/lib/billomat/gateway.rb b/lib/billomat/gateway.rb index 8a6db0c..65cfd3a 100644 --- a/lib/billomat/gateway.rb +++ b/lib/billomat/gateway.rb @@ -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 diff --git a/lib/billomat/models.rb b/lib/billomat/models.rb deleted file mode 100644 index 5c69bc8..0000000 --- a/lib/billomat/models.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require 'billomat/models/base' -require 'billomat/models/client' -require 'billomat/models/credit_note' -require 'billomat/models/credit_note_item' -require 'billomat/models/invoice' -require 'billomat/models/invoice_comment' -require 'billomat/models/invoice_item' -require 'billomat/models/invoice_payment' -require 'billomat/models/contact' -require 'billomat/models/tag' -require 'billomat/models/template' - -module Billomat - # Models represent a resource in the API, e.g. invoices, clients. - module Models; end -end diff --git a/lib/billomat/models/base.rb b/lib/billomat/models/base.rb index 1425f8b..8cfab72 100644 --- a/lib/billomat/models/base.rb +++ b/lib/billomat/models/base.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'ostruct' - module Billomat module Models # This class is the base for all other models (resources). diff --git a/lib/billomat/search.rb b/lib/billomat/search.rb index 3422047..a659be1 100644 --- a/lib/billomat/search.rb +++ b/lib/billomat/search.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'uri' - module Billomat # This class provides the possibility to query the resources. class Search diff --git a/spec/support/suite_context.rb b/spec/support/suite_context.rb index 68f89c0..935ad4c 100644 --- a/spec/support/suite_context.rb +++ b/spec/support/suite_context.rb @@ -5,6 +5,7 @@ puts <