conventional_extensions 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a9c04f9382953e08d30d29f802edd622ef28f91da4314d77c21d7f0eb09f2fe
4
- data.tar.gz: b51b6c673302e93aec88613b42e1e7c44a7c0d4055165057ffac546614fd357f
3
+ metadata.gz: '060300878dfd038ee631b86d3d16bb3a1da4ce4de8c5e4d5b0c2f58299c04447'
4
+ data.tar.gz: 10a0f2d7c828792caaa3d28c95856a68c77e2afb4a5f3ec8f7cdc90e7a2020a2
5
5
  SHA512:
6
- metadata.gz: ed770c9838eb07f7c752bf2f1973edf9a5ad77511ec6d939600114d203a3e6db9270d5ec8ef3b354c6914728ca0afe259c128d569aef0c9639928c6c4ed36895
7
- data.tar.gz: d5035eff9ad821562a828dc671927a89fffe2ad1f1fe49d91b3c3147131837ecc9c82caa8adaaf26ab48149bc92a9520a3bce514efdd11380a53ff36fa657b18
6
+ metadata.gz: c1bdc8bfe33c5a16454714d07a20faba6f8211cb8515856613887f21e3c6c5ce7b7119da58b90510b9078f01e8d947c1696b0b1b03b3d0882e598833e45f74b8
7
+ data.tar.gz: 334827497c824fba2a4bbf705612387c420311d52a093b78a3d70241ba6baa34a54729cfaa9081fcf9358ff23e14d26beba5640dba7132b553d0eaaaa7ac3ace
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2022-11-23
4
+
5
+ - Ignore extensions folders automatically in Rails.
6
+
7
+ We've added a Railtie which automatically ignores every extensions folder by running `Rails.autoloaders.main.ignore "**/extensions/**.rb"`.
8
+
9
+ Fixed #8.
10
+
11
+ - Remove automatic extension loading for Active Records.
12
+
13
+ Due to the automatic extension loading in Active Record, there was no way for people to manually call `load_extensions` if they wanted to. And implementation wise there wasn't a way to sort that out. So the automatic loading support is out.
14
+
15
+ Though you can get the old behavior back with this, which calls `load_extensions` when a new class inherits from `ApplicationRecord`:
16
+
17
+ ```ruby
18
+ # app/models/application_record.rb
19
+ class ApplicationRecord < ActiveRecord::Base
20
+ extend ConventionalExtensions.load_on_inherited
21
+ end
22
+ ```
23
+
24
+ Fixed #10.
25
+
3
26
  ## [0.3.0] - 2022-09-27
4
27
 
5
28
  - Fixes defining a nested extension, e.g. `Organization::User` with `app/models/organization/user/extensions/`.
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "minitest", "~> 5.0"
11
+
12
+ gem "debug", "~> 1.6"
data/Gemfile.lock CHANGED
@@ -1,13 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conventional_extensions (0.3.0)
4
+ conventional_extensions (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ debug (1.6.3)
10
+ irb (>= 1.3.6)
11
+ reline (>= 0.3.1)
12
+ io-console (0.5.11)
13
+ irb (1.4.3)
14
+ reline (>= 0.3.0)
9
15
  minitest (5.16.3)
10
16
  rake (13.0.6)
17
+ reline (0.3.1)
18
+ io-console (~> 0.5)
11
19
 
12
20
  PLATFORMS
13
21
  arm64-darwin-20
@@ -15,6 +23,7 @@ PLATFORMS
15
23
 
16
24
  DEPENDENCIES
17
25
  conventional_extensions!
26
+ debug (~> 1.6)
18
27
  minitest (~> 5.0)
19
28
  rake (~> 13.0)
20
29
 
data/README.md CHANGED
@@ -7,7 +7,7 @@ The entry point is to call `load_extensions` right after a class is originally d
7
7
  ```ruby
8
8
  # lib/post.rb
9
9
  class Post < SomeSuperclass
10
- load_extensions # Loads every Ruby file under `lib/post/extensions/*.rb`.
10
+ load_extensions # Loads every Ruby file found with `lib/post/extensions/*.rb`.
11
11
  end
12
12
  ```
13
13
 
@@ -17,7 +17,7 @@ Since the loading above happens after the `Post` constant has been defined, we c
17
17
 
18
18
  ```ruby
19
19
  # lib/post/extensions/mailroom.rb
20
- class Post # <- Post is reopened here and so there's no superclass mismatch error
20
+ class Post # <- Post is reopened here, so there's no superclass mismatch error
21
21
  def mailroom
22
22
  puts "you've got mail"
23
23
  end
@@ -102,6 +102,17 @@ class Subclass < BaseClass
102
102
  end
103
103
  ```
104
104
 
105
+ This works for Active Record too, and you can add this to your `ApplicationRecord`:
106
+
107
+ ```ruby
108
+ # app/models/application_record.rb
109
+ class ApplicationRecord < ActiveRecord::Base
110
+ extend ConventionalExtensions.load_on_inherited
111
+ end
112
+ ```
113
+
114
+ Note that you lose support for calling `load_extensions` manually because of the implementation, so it's all or nothing.
115
+
105
116
  ## A less boilerplate heavy alternative to `ActiveSupport::Concern` for Active Records
106
117
 
107
118
  Typically, when writing an app domain model with `ActiveSupport::Concern` your object graph looks like this:
@@ -143,7 +154,8 @@ With ConventionalExtensions you'd write this instead:
143
154
 
144
155
  ```ruby
145
156
  # app/models/post.rb
146
- class Post < ApplicationRecord # ConventionalExtensions automatically loads extensions for Active Record models.
157
+ class Post < ApplicationRecord
158
+ load_extensions # Loads every Ruby file found with `app/models/post/extensions/*.rb`.
147
159
  end
148
160
 
149
161
  # app/models/post/extensions/cool.rb
@@ -167,6 +179,12 @@ There are places where concerns are more suited:
167
179
  * Multi-model concerns in `app/models/concerns`, you'd need modules to help with that.
168
180
  * Needing to include multiple levels of modules and have them all inserted directly on the base class, concerns have this built in, but ConventionalExtensions can't support that. It's a rare use case nonetheless.
169
181
 
182
+ ## Using with Zeitwerk
183
+
184
+ If you're using Zeitwerk to eager load your app or lib code, you may need to ignore the nested extensions folders so Zeitwerk won't expect them to contain code following its naming conventions.
185
+
186
+ We handle this for Rails through `Rails.autoloaders.main.ignore "**/extensions/**.rb"`. Feel free to use this `ignore` call on your Zeitwerk loader.
187
+
170
188
  ## Installation
171
189
 
172
190
  Install the gem and add to the application's Gemfile by executing:
@@ -0,0 +1,5 @@
1
+ class ConventionalExtensions::Railtie < Rails::Railtie
2
+ initializer "conventional_extensions.ignore_extensions_directories" do
3
+ Rails.autoloaders.main.ignore "**/extensions/**.rb"
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConventionalExtensions
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -32,4 +32,4 @@ module ConventionalExtensions
32
32
  autoload :Loader, "conventional_extensions/loader"
33
33
  end
34
34
 
35
- defined?(ActiveSupport.on_load) and ActiveSupport.on_load(:active_record) { extend ConventionalExtensions.load_on_inherited }
35
+ require_relative "conventional_extensions/railtie" if defined?(Rails::Railtie)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conventional_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Timm Hansen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-27 00:00:00.000000000 Z
11
+ date: 2022-11-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -26,6 +26,7 @@ files:
26
26
  - conventional_extensions.gemspec
27
27
  - lib/conventional_extensions.rb
28
28
  - lib/conventional_extensions/loader.rb
29
+ - lib/conventional_extensions/railtie.rb
29
30
  - lib/conventional_extensions/version.rb
30
31
  homepage: https://github.com/kaspth/conventional_extensions
31
32
  licenses:
@@ -49,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  - !ruby/object:Gem::Version
50
51
  version: '0'
51
52
  requirements: []
52
- rubygems_version: 3.3.21
53
+ rubygems_version: 3.3.24
53
54
  signing_key:
54
55
  specification_version: 4
55
56
  summary: ConventionalExtensions sets up a file naming convention to extend your domain