rails_drivers 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3f6def3a021505dcc8e3e168a55055150e52682c55936201375c17c44737141
4
- data.tar.gz: 2d2676eb32495f0439ae729b6d859090ac05b8f68aeda464d48ecd3a8be79e57
3
+ metadata.gz: 1c7d656ab0c27596f48e919c471b2ccfa30859bc808ae8942e24d8924fbbe7e7
4
+ data.tar.gz: 65275e5544bb6b1a76c82c106fd2f8cd7df6a346422a8accf655fb5026df06d0
5
5
  SHA512:
6
- metadata.gz: 32b30893d088238f00b472f8b9d68045ed8462b14d15f537c5770f5034460307297c298b1205a5e37437895aef0511e4f21a54fa6c7c85848d3b0cb671d210a1
7
- data.tar.gz: c8cbcc9199295015ad8779db3283753eb93bc702776a8bcf0ceea43f7ad1543eb71d2a84470bbd9de6b97191a5c1d98dfb902aff61c140915aa8d4d8d8660855
6
+ metadata.gz: c03812aa671e2305a5dd04a373a4bb2fe06bb37f307ade5bf3a74398b8d0722c97b94a8cb71f372eb53699bc5101260804da1b9d3f98ac34f13c3fe4740485b5
7
+ data.tar.gz: c43ef0a47625c66942ef8c841b917047bf6b63945d9ac483fe202d5630b0da8b07088ba586acaceab1606de128e749422ed547f3498be191864e4478ee49ae48
data/README.md CHANGED
@@ -11,7 +11,7 @@ Technically speaking, "driver" is just a fancy name for code that live in a diff
11
11
 
12
12
  The "main app" refers to the files inside your `<project root>/app` directory.
13
13
 
14
- If your test suite is good enough (see [Testing for coupling](#testing-for-coupling), you can test that these rules are adhered to by selectively adding and removing drivers before running your tests.
14
+ If your test suite is good enough (see [Testing for coupling](#testing-for-coupling)), you can test that these rules are adhered to by selectively adding and removing drivers before running your tests.
15
15
 
16
16
  ## Aren't these just engines?
17
17
 
@@ -44,7 +44,7 @@ Run `rails g driver my_new_driver_name` to get a scaffold driver.
44
44
  `bundle exec driver my_driver_name generate migration blah etc_etc:string`
45
45
 
46
46
  The `driver` utility technically works with other generators and rake tasks, but is only guaranteed to work with migrations.
47
- The reason is that some generators have hard-coded path strongs, rather than using the Rails path methods.
47
+ The reason is that some generators have hard-coded path strings, rather than using the Rails path methods.
48
48
 
49
49
  ### Creating a rake task in a driver
50
50
 
@@ -132,6 +132,8 @@ Of course there's nothing stopping you from using if-statements to detect whethe
132
132
  ## Installation
133
133
  Add this line to your application's Gemfile:
134
134
 
135
+ ### Install the gem
136
+
135
137
  ```ruby
136
138
  gem 'rails_drivers'
137
139
  ```
@@ -141,15 +143,21 @@ And then execute:
141
143
  $ bundle install
142
144
  ```
143
145
 
144
- Finally, add these lines to your routes.rb:
146
+ ### Update routes file
147
+
148
+ Add these lines to your routes.rb:
145
149
 
146
150
  ```ruby
151
+ # config/routes.rb in your main Rails app
152
+
147
153
  require 'rails_drivers/routes'
148
154
 
149
155
  # This can go before or after your application's route definitions
150
156
  RailsDrivers::Routes.load_driver_routes
151
157
  ```
152
158
 
159
+ This will tell your main Rails app to load the `routes.rb` files generated in each of your drivers.
160
+
153
161
  ### RSpec
154
162
 
155
163
  If you use RSpec with FactoryBot, add these lines to your `spec/rails_helper.rb` or `spec/spec_helper.rb`:
@@ -18,6 +18,7 @@ module RailsDrivers
18
18
 
19
19
  @@driver_extensions = possible_extensions.map do |path|
20
20
  require_dependency path
21
+
21
22
  %r{drivers/(?<driver_name>[^/]+)/extensions} =~ path
22
23
 
23
24
  extension = "#{driver_name.classify}::#{name}Extension".constantize
@@ -19,6 +19,19 @@ module RailsDrivers
19
19
  end
20
20
  end
21
21
 
22
+ # Since the extensions directory exists for organizational
23
+ # purposes and does not define modules with namespace `Extention`
24
+ # we need to use Zeitwerk collapse function.
25
+ #
26
+ # see https://github.com/fxn/zeitwerk#collapsing-directories
27
+ if Rails::VERSION::MAJOR >= 6
28
+ initializer 'rails_drivers.autoloader.collapse' do
29
+ Rails.autoloaders.each do |loader|
30
+ loader.collapse('drivers/*/extensions')
31
+ end
32
+ end
33
+ end
34
+
22
35
  config.before_configuration { setup_paths }
23
36
  config.after_initialize { RailsDrivers.freeze! }
24
37
  end
@@ -34,20 +34,28 @@ module RailsDrivers
34
34
  end
35
35
 
36
36
  def replace_rails_paths_with_driver(driver_name)
37
+ rails_config.autoload_paths << "#{rails_config.root}/drivers"
38
+
37
39
  DRIVER_PATHS.each do |path|
38
40
  rails_config.paths[path] = "drivers/#{driver_name}/#{path}"
39
- rails_config.autoload_paths = ["#{rails_config.root}/drivers/#{driver_name}/lib"]
41
+ rails_config.autoload_paths += [
42
+ "#{rails_config.root}/drivers/#{driver_name}/lib"
43
+ ]
40
44
  end
41
45
  end
42
46
 
43
- def add_every_driver_to_rails_paths
47
+ def add_every_driver_to_rails_paths # rubocop:disable Metrics/AbcSize
48
+ rails_config.autoload_paths << "#{rails_config.root}/drivers"
49
+
44
50
  Dir['drivers/*'].each do |driver|
45
51
  DRIVER_PATHS.each do |path|
46
52
  rails_config.paths[path] << "#{driver}/#{path}"
47
53
  end
48
54
 
49
55
  # We want to autoload driver/*/lib folders
50
- rails_config.autoload_paths += ["#{rails_config.root}/#{driver}/lib"]
56
+ rails_config.autoload_paths += [
57
+ "#{rails_config.root}/#{driver}/lib"
58
+ ]
51
59
  end
52
60
  end
53
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsDrivers
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_drivers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Baillie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-14 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: webpacker
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.5'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.5'
82
+ version: '0'
83
83
  description: Like Rails Engines, but without the friction. Your Rails app can't access
84
84
  them, and they can't access each other.
85
85
  email: