From 05c2f271523682649c1f6975cc668c1625273a7e Mon Sep 17 00:00:00 2001 From: Florent Piteau Date: Fri, 18 Aug 2023 17:42:13 +0200 Subject: [PATCH] Don't try to load generators if ActiveRecord is not loaded The generators are dependent on ActiveRecord, so if you are using rails without active_record, mobility would not load : ``` `require': cannot load such file -- rails/generators/active_record (LoadError) ``` Closes #627 --- CHANGELOG.md | 6 ++++++ lib/mobility.rb | 2 +- spec/generators/rails/mobility/install_generator_spec.rb | 2 +- .../rails/mobility/translations_generator_spec.rb | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e27ffef..c329476f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 1.3 +### Unreleased + +- Don't try to load generators if Rails is loaded but AR is not + ([#627](https://github.com/shioyama/mobility/pull/627)), thanks + [flop](https://github.com/flop)! + ### 1.3.0.rc2 - Pass `coder` as keyword argument to `serialize` (ActiveRecord version > 7.1) diff --git a/lib/mobility.rb b/lib/mobility.rb index dd3f9d05..4163b429 100644 --- a/lib/mobility.rb +++ b/lib/mobility.rb @@ -90,7 +90,7 @@ class Error < StandardError CALL_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?]?\z/ private_constant :CALL_COMPILABLE_REGEXP - require "rails/generators/mobility/generators" if defined?(Rails) + require "rails/generators/mobility/generators" if defined?(Rails) && defined?(ActiveRecord) class << self def extended(model_class) diff --git a/spec/generators/rails/mobility/install_generator_spec.rb b/spec/generators/rails/mobility/install_generator_spec.rb index d671db70..cba3f5dc 100644 --- a/spec/generators/rails/mobility/install_generator_spec.rb +++ b/spec/generators/rails/mobility/install_generator_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -return unless defined?(Rails) +return unless defined?(Rails) && defined?(ActiveRecord) require "rails/generators/mobility/install_generator" diff --git a/spec/generators/rails/mobility/translations_generator_spec.rb b/spec/generators/rails/mobility/translations_generator_spec.rb index 221de688..6b2a9b30 100644 --- a/spec/generators/rails/mobility/translations_generator_spec.rb +++ b/spec/generators/rails/mobility/translations_generator_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -return unless defined?(Rails) +return unless defined?(Rails) && defined?(ActiveRecord) require "rails/generators/mobility/translations_generator"