rails_drivers 0.1.0 → 0.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 +4 -4
- data/README.md +45 -5
- data/lib/rails_drivers/setup.rb +1 -0
- data/lib/rails_drivers/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 575d8e9162b65431801bf6d419fe5fca254d65fdd3a840877ea1a0c186bd90bd
|
|
4
|
+
data.tar.gz: 06e51508f802ee83223d9b9a0bea05f91f93d0813cf1aba6503f29d63cb9d631
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65a00d958eaf2d888c565149f840ac43f0048587b332c433c33734e38652bb31d5a90c6d3bb439eaca6c5e3c1b7b2fa7d9703f97a45dad40b059a3f3e05e298f
|
|
7
|
+
data.tar.gz: b5a03060c043e906ea25955a23513a6939a532fecb560c81cb3bc9075d708195d9bf60135e620a268ca025ec81a9ea90b17c0f0baf957761b091b330ef763a73
|
data/README.md
CHANGED
|
@@ -4,20 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
Each driver is like a mini Rails app that has full access to the main app. A driver has its own `app`, `config`, `spec`, and `db` folder.
|
|
6
6
|
|
|
7
|
-
Technically speaking, drivers are just a
|
|
7
|
+
Technically speaking, drivers are just a fancy name for putting code into a different folder. The advantage of doing this is that it provides clear-cut separation of concerns. If we follow a couple of simple rules, we can actually test that separation:
|
|
8
8
|
|
|
9
9
|
- Drivers should not touch other drivers
|
|
10
10
|
- The main app should not touch drivers directly
|
|
11
11
|
|
|
12
12
|
The "main app" refers to the files inside your `<project root>/app` directory.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
If your test suite is good, 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
|
|
|
18
18
|
Very similar, yes. They use the same Rails facilities for adding new `app` paths, etc.
|
|
19
19
|
|
|
20
|
-
But Drivers have
|
|
20
|
+
But Drivers have less friction. They can be freely added and removed from your project without breaking anything. There's no need to mess around with gems, vendoring, or dummy apps.
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
@@ -72,13 +72,15 @@ And then execute:
|
|
|
72
72
|
$ bundle install
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
Add this line to your routes.rb
|
|
75
|
+
Add this line to your routes.rb:
|
|
76
76
|
|
|
77
77
|
```ruby
|
|
78
78
|
require 'rails_drivers/routes'
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
### RSpec
|
|
82
|
+
|
|
83
|
+
If you use RSpec, add these lines to your `spec/rails_helper.rb` or `spec/spec_helper.rb`:
|
|
82
84
|
|
|
83
85
|
```ruby
|
|
84
86
|
Dir[Rails.root.join("drivers/*/spec/support/*.rb")].each { |f| require f }
|
|
@@ -90,5 +92,43 @@ RSpec.configure do |config|
|
|
|
90
92
|
end
|
|
91
93
|
```
|
|
92
94
|
|
|
95
|
+
### Webpacker
|
|
96
|
+
|
|
97
|
+
If you use Webpacker, take a look at this snippet. You'll want to add the code between the comments:
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
// config/webpack/environment.js
|
|
101
|
+
const { environment } = require('@rails/webpacker')
|
|
102
|
+
|
|
103
|
+
//// Begin driver code ////
|
|
104
|
+
const { config } = require('@rails/webpacker')
|
|
105
|
+
const { sync } = require('glob')
|
|
106
|
+
const { basename, dirname, join, relative, resolve } = require('path')
|
|
107
|
+
const extname = require('path-complete-extname')
|
|
108
|
+
|
|
109
|
+
const getExtensionsGlob = () => {
|
|
110
|
+
const { extensions } = config
|
|
111
|
+
return extensions.length === 1 ? `**/*${extensions[0]}` : `**/*{${extensions.join(',')}}`
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const addToEntryObject = (sourcePath) => {
|
|
115
|
+
const glob = getExtensionsGlob()
|
|
116
|
+
const rootPath = join(sourcePath, config.source_entry_path)
|
|
117
|
+
const paths = sync(join(rootPath, glob))
|
|
118
|
+
paths.forEach((path) => {
|
|
119
|
+
const namespace = relative(join(rootPath), dirname(path))
|
|
120
|
+
const name = join(namespace, basename(path, extname(path)))
|
|
121
|
+
environment.entry.set(name, resolve(path))
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
sync('drivers/*').forEach((driverPath) => {
|
|
126
|
+
addToEntryObject(join(driverPath, config.source_path));
|
|
127
|
+
})
|
|
128
|
+
//// End driver code ////
|
|
129
|
+
|
|
130
|
+
module.exports = environment
|
|
131
|
+
```
|
|
132
|
+
|
|
93
133
|
## License
|
|
94
134
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/rails_drivers/setup.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_drivers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.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: 2019-12-
|
|
11
|
+
date: 2019-12-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webpacker
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.5'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.5'
|
|
55
69
|
description: Like Rails Engines, but without the friction. Your Rails app can't access
|
|
56
70
|
them, and they can't access each other.
|
|
57
71
|
email:
|