Skip to content

Commit

Permalink
Don't try to load generators if ActiveRecord is not loaded
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Florent Piteau authored and shioyama committed Mar 20, 2024
1 parent cad61f9 commit 05c2f27
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/mobility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/generators/rails/mobility/install_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

return unless defined?(Rails)
return unless defined?(Rails) && defined?(ActiveRecord)

require "rails/generators/mobility/install_generator"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

return unless defined?(Rails)
return unless defined?(Rails) && defined?(ActiveRecord)

require "rails/generators/mobility/translations_generator"

Expand Down

0 comments on commit 05c2f27

Please sign in to comment.