Skip to content

Commit

Permalink
Merge pull request #71 from customink/am/circbox
Browse files Browse the repository at this point in the history
Compatibility with circuitbox 2.0.0
  • Loading branch information
a-maas authored Apr 3, 2024
2 parents 4cbfa57 + a3c5ab4 commit 0b1d916
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 145 deletions.
78 changes: 0 additions & 78 deletions .circleci/config.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "CI"
on: push
jobs:
test:
strategy:
fail-fast: false
matrix:
ruby: ["2.5", "2.7", "3.0", "3.1", "3.2"]
gemfile:
- circuitbox_1
- circuitbox_2
exclude:
- ruby: "3.2"
gemfile: "circuitbox_1"
- ruby: "3.1"
gemfile: "circuitbox_1"
- ruby: "3.0"
gemfile: "circuitbox_1"
- ruby: "2.5"
gemfile: "circuitbox_2"

runs-on: ubuntu-22.04
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
BUNDLE_PATH_RELATIVE_TO_CWD: true
steps:
- name: Checkout code
uses: actions/checkout@v3
# Add or replace dependency steps here
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
cache-version: 3
# Add or replace test runners here
- name: Run tests
run: bin/rake test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/test/reports/
/tmp/
Gemfile.lock
gemfiles/*.gemfile.lock
.env.*
.ruby-version
.byebug_history
7 changes: 7 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appraise "circuitbox-1" do
gem "circuitbox", "~> 1.1.1"
end

appraise "circuitbox-2" do
gem "circuitbox", "~> 2.0.0"
end
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ gemspec

group :test do
gem 'minitest-ci', require: false
gem 'simplecov', '< 0.18', require: false
end
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "bundler/gem_tasks"
require "rake/testtask"
require 'wwtd/tasks'

Rake::TestTask.new(:test) do |t|
t.libs << "test"
Expand Down
109 changes: 109 additions & 0 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../Gemfile", __dir__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, ".locked")
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_requirement
@bundler_requirement ||=
env_var_version ||
cli_arg_version ||
bundler_requirement_for(lockfile_version)
end

def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless version

bundler_gem_version = Gem::Version.new(version)

bundler_gem_version.approximate_recommendation
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
8 changes: 3 additions & 5 deletions bin/rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("../bundle", __FILE__)
bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Expand Down
10 changes: 2 additions & 8 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,5 @@
set -e
cd "$(dirname "$0")/.."

if [[ -z "$CI" ]]; then
# Bundle each ruby version
rm -rf Gemfile.lock
gem install wwtd
wwtd --only-bundle
else
bundle --quiet
fi
bundle --quiet

2 changes: 1 addition & 1 deletion bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
# system('RAILS_ENV=test bin/rails db:setup')

puts '== Running tests =='
command = ENV['CI'] ? 'bundle exec rake' : 'wwtd'
command = 'bundle exec rake'
system("#{command}") || abort
11 changes: 11 additions & 0 deletions gemfiles/circuitbox_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "circuitbox", "~> 1.1.1"

group :test do
gem "minitest-ci", require: false
end

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

source "https://rubygems.org"

gem "circuitbox", "~> 2.0.0"

group :test do
gem "minitest-ci", require: false
end

gemspec path: "../"
31 changes: 30 additions & 1 deletion lib/vertex_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ def configuration
def reconfigure!
@configuration = Configuration.new
yield(@configuration) if block_given?
reconfigure_circuitbox
end

def configure
yield(configuration)
reconfigure_circuitbox
end

def quotation(payload)
Expand All @@ -76,12 +78,39 @@ def tax_area(payload)
end

def circuit
return unless configuration.circuit_config && defined?(Circuitbox)
return unless circuit_configured?

Circuitbox.circuit(
Configuration::CIRCUIT_NAME,
configuration.circuit_config
)
end

private

def reconfigure_circuitbox
return unless circuitbox_defined?

if Circuitbox.respond_to?(:reset)
Circuitbox.reset
else
Circuitbox.configure do |config|
config.default_circuit_store = configured_circuit_store
end
end
end

def configured_circuit_store
(configuration.circuit_config && configuration.circuit_config[:circuit_store]) || Circuitbox::MemoryStore.new
end

def circuit_configured?
configuration.circuit_config && circuitbox_defined?
end

def circuitbox_defined?
defined?(Circuitbox)
end
end

class Error < StandardError; end
Expand Down
2 changes: 1 addition & 1 deletion lib/vertex_client/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def resource_config

def call_with_circuit_if_available
if VertexClient.circuit
VertexClient.circuit.run { yield }
VertexClient.circuit.run(exception: false) { yield }
else
begin
yield
Expand Down
2 changes: 1 addition & 1 deletion lib/vertex_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module VertexClient
VERSION = '0.10.2'
VERSION = '0.11.0'
end
Loading

0 comments on commit 0b1d916

Please sign in to comment.