Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 5 additions & 0 deletions lib/pact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

require 'pact/railtie' if defined?(Rails::Railtie)

# Load blank?/present? polyfill before Zeitwerk eager-loads the rest of the gem.
# Skipped if active_support (or anything else) has already defined these methods.
require 'pact/support/blank'
Comment thread
Saup21 marked this conversation as resolved.
Outdated

module Pact
class Error < StandardError; end

Expand Down Expand Up @@ -41,6 +45,7 @@ def self.configuration
loader.ignore("#{__dir__}/pact/version.rb")
loader.ignore("#{__dir__}/pact/rspec.rb")
loader.ignore("#{__dir__}/pact/rspec")
loader.ignore("#{__dir__}/pact/support/blank.rb")
loader.ignore("#{__dir__}/pact/railtie.rb") unless defined?(Rails::Railtie)

loader.setup
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/rspec/support/webmock/webmock_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module WebmockHelpers
def self.turned_off
yield unless defined?(::WebMock)
return yield unless defined?(::WebMock)

allow_net_connect = WebMock::Config.instance.allow_net_connect
allow_localhost = WebMock::Config.instance.allow_localhost
Expand Down
40 changes: 40 additions & 0 deletions lib/pact/support/blank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

# Minimal blank?/present? polyfill for when active_support is not loaded.
# Skipped entirely if Object already responds to blank? (e.g. active_support is present).
unless Object.method_defined?(:blank?)
class NilClass
def blank? = true
def present? = false
end

class FalseClass
def blank? = true
def present? = false
end

class TrueClass
def blank? = false
def present? = true
end

class String
def blank? = empty? || strip.empty?
def present? = !blank?
end

class Array
def blank? = empty?
def present? = !empty?
end

class Hash
def blank? = empty?
def present? = !empty?
end

class Object
def blank? = !self
def present? = !!self
end
end
6 changes: 6 additions & 0 deletions pact.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Gem::Specification.new do |gem|
'documentation_uri' => 'https://github.com/pact-foundation/pact-ruby/blob/master/README.md'
}

# Optional runtime dependencies (not required by pact itself):
# active_support — if already loaded, its blank?/present? take precedence over
# pact's built-in polyfill (lib/pact/support/blank.rb).
# webmock — only needed for WebMock integration via WebmockHelpers.
# Require it yourself before using that helper.

# Core dependencies (code loading)
gem.add_dependency 'zeitwerk', '~> 2.3'
# For Pact support via Pact Rust Core
Expand Down
Loading