rails_drivers 0.1.0 → 0.2.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: '03862c5a464a55793074ecb863ac4e7eb4530172923a5f0a8207d8051bf54f96'
4
- data.tar.gz: ffc80ffc2db7d8f71f5598f388fa3cce4efc8399362aa841d3b21cc776508df3
3
+ metadata.gz: 575d8e9162b65431801bf6d419fe5fca254d65fdd3a840877ea1a0c186bd90bd
4
+ data.tar.gz: 06e51508f802ee83223d9b9a0bea05f91f93d0813cf1aba6503f29d63cb9d631
5
5
  SHA512:
6
- metadata.gz: 2a89e522b5a3fac4be2323be01f8d9e2085e2b54ceee263b1835b75bbae7df2397d68b57c690bcf11f7df1ca5efce2be9add211bcd7a247a8d96e3d3dc1bf7e0
7
- data.tar.gz: df27e76af55099c0031644db8a156124ffa2b72d9ef67ef6a4427119f3c35497979814348bf86cf8ec4a20065834d6dc3839f27647f248eccee2cf2c16812fff
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 way to put code into a different folder, but there are some rules we like to follow in order to reduce application complexity:
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
- Thankfully, we can test that these rules are adhered to by removing drivers before running the test suite.
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 one useful property: they can be freely added and removed from your project without breaking anything.
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
- (Optional) Add these lines to your `spec/rails_helper.rb`
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).
@@ -4,6 +4,7 @@ module RailsDrivers
4
4
  module Setup
5
5
  DRIVER_PATHS = %w[
6
6
  app
7
+ app/assets
7
8
  app/models
8
9
  app/views
9
10
  app/controllers
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsDrivers
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.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-12 00:00:00.000000000 Z
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: