From 7624be4e735b2fe6e03156c4de9debfeae3900bf Mon Sep 17 00:00:00 2001 From: Henrik Nyh Date: Sun, 22 Dec 2024 21:46:30 +0100 Subject: [PATCH] Support Active Record <8.0.1 ActiveModel::API is only included in ActiveRecord::Base since https://github.com/rails/rails/commit/2c57ec6a179e5fb851aca1bdc4b11b17d99a93c8. It gets a little messy to explicitly handle ActiveRecord before then. I'd rather not run Active Record in specs and need to run a sqlite DB or whatever. Instead, let us for now settle for mixing this into all objects, like with_options. The gem is still conceptually for ActiveModel/ActiveRecord, even though it no longer strictly depends on either outside of specs. --- CHANGELOG.md | 4 ++++ Gemfile.lock | 3 +-- activemodel-with_conditions.gemspec | 2 -- lib/with_conditions.rb | 15 ++++----------- lib/with_conditions/version.rb | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53d8581..0398cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.1.0] - 2024-12-22 + +- Support Active Record prior to 8.0.1 + ## [1.0.0] - 2024-12-22 - Initial release diff --git a/Gemfile.lock b/Gemfile.lock index 6422333..1563d85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,7 @@ PATH remote: . specs: - activemodel-with_conditions (1.0.0) - activemodel + activemodel-with_conditions (1.1.0) GEM remote: https://rubygems.org/ diff --git a/activemodel-with_conditions.gemspec b/activemodel-with_conditions.gemspec index 93c47cb..f166e0c 100644 --- a/activemodel-with_conditions.gemspec +++ b/activemodel-with_conditions.gemspec @@ -28,6 +28,4 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - - spec.add_dependency "activemodel" end diff --git a/lib/with_conditions.rb b/lib/with_conditions.rb index 6b65822..91db1cb 100644 --- a/lib/with_conditions.rb +++ b/lib/with_conditions.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "active_model" require_relative "with_conditions/options_merger" require_relative "with_conditions/version" @@ -16,13 +15,7 @@ def with_conditions(if: nil, unless: nil, &block) end end -module ActiveModel - module API - singleton_class.prepend(Module.new do - def included(klass) - super - klass.extend WithConditions - end - end) - end -end +# To keep things simple, we include this in all objects, like `with_options`. +# +# Otherwise we would want specs that include Active Record, and we'd want to consider that different versions of Rails use Active Model in different ways (e.g. only recent Rails per 2024-12-22 include ActiveModel::API in ActiveRecord::Base`). +Object.extend WithConditions diff --git a/lib/with_conditions/version.rb b/lib/with_conditions/version.rb index db25bbd..17e221f 100644 --- a/lib/with_conditions/version.rb +++ b/lib/with_conditions/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module WithConditions - VERSION = "1.0.0" + VERSION = "1.1.0" end