bullet_train-routes 1.0.0 → 1.46.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 +126 -12
- data/lib/bullet_train/routes/engine.rb +12 -0
- data/lib/bullet_train/routes/mapper_extensions.rb +175 -89
- data/lib/bullet_train/routes/version.rb +1 -1
- data/lib/bullet_train/routes.rb +16 -4
- metadata +37 -12
- data/lib/bullet_train/routes/railtie.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e7536d1d8b2c88efa0400a44bdb3fa12b8bb315356989cdc2aba88ad8e8517c
|
|
4
|
+
data.tar.gz: cabad72bae6eed0bf9736222220bcf92551c26caa682fcb9903835ba8541ad80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3be977244642d5ae0065c2d7feeae26d8646aa2affd806aa512bbafe80e7d9110dc35c509df75a256dec1b0e72d42836a7cdcfce208d17b361bcdceda3243328
|
|
7
|
+
data.tar.gz: 6871c02b2599c512f4de97efece758866569c76f4cf6c26623b2ae04338f560e3334a920d1fd5502c27ae470a2ba729bcb1c325e2192a6ef751494a6e2667fe2
|
data/README.md
CHANGED
|
@@ -1,8 +1,130 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Bullet Train Routes
|
|
2
|
+
Bullet Train Routes provides a vastly simplified method for defining shallow, nested resource routes in Rails applications when modules and namespaces are involved. We do this by introducing a `model` method to the Rails routing DSL, which serves as an interchangable substitute for the `resources` method.
|
|
3
3
|
|
|
4
|
-
##
|
|
5
|
-
|
|
4
|
+
## Why?
|
|
5
|
+
As Rails applications grow and developers start reaching for tools like modules and namespaces to organize their domain model, it can be incredibly challenging to generate sensible routes and URLs using the traditional Rails routing DSL.
|
|
6
|
+
|
|
7
|
+
For example, if you've got a `Project` model and a `Projects::Deliverable` model nested under it, the following would be sensible URLs:
|
|
8
|
+
|
|
9
|
+
- `/projects/1` for a project show page.
|
|
10
|
+
- `/projects/1/deliverables` for the deliverables index page.
|
|
11
|
+
- `/projects/deliverables/2` for a deliverable show page.
|
|
12
|
+
|
|
13
|
+
To produce these URLs with the standard Rails routing DSL, you'll end up with the following:
|
|
14
|
+
|
|
15
|
+
### ❌ Hard Example
|
|
16
|
+
```ruby
|
|
17
|
+
collection_actions = [:index, :new, :create]
|
|
18
|
+
|
|
19
|
+
resources :projects do
|
|
20
|
+
scope module: 'projects' do
|
|
21
|
+
resources :deliverables, only: collection_actions
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
namespace :projects do
|
|
26
|
+
resources :deliverables, except: collection_actions
|
|
27
|
+
end
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This is just one example, and not even the most complicated. Previously [we published a comprehensive blog post](https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/) to try and help developers with various examples like this, but there was no helping that the resulting code would be very difficult for the next developer to understand and maintain later.
|
|
31
|
+
|
|
32
|
+
> In addition to all of this, trying to automatically generate these routes proved to be one of the most complicated and error-prone pieces of [Super Scaffolding](https://bullettrain.co/docs/super-scaffolding).
|
|
33
|
+
|
|
34
|
+
With Bullet Train Routes, the example above can be simplified like so:
|
|
35
|
+
|
|
36
|
+
### ✅ Easy Example
|
|
37
|
+
```ruby
|
|
38
|
+
model "Project" do
|
|
39
|
+
model "Projects::Deliverable"
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Other Examples
|
|
44
|
+
Here are additional before and after comparisons inspired by some of the examples in [our original blog post](https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/).
|
|
45
|
+
|
|
46
|
+
### `Projects::Deliverable` and `Objective` Nested Under It
|
|
47
|
+
|
|
48
|
+
If you're nesting a resource that isn't in the same namespace, you traditionally end up with a route definition that looks like this:
|
|
49
|
+
|
|
50
|
+
### ❌ Hard Example
|
|
51
|
+
```ruby
|
|
52
|
+
namespace :projects do
|
|
53
|
+
resources :deliverables
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
resources :projects_deliverables, path: 'projects/deliverables' do
|
|
57
|
+
resources :objectives
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This produces the following URLs:
|
|
62
|
+
|
|
63
|
+
- `/projects/deliverables/1` for a deliverable show view.
|
|
64
|
+
- `/projects/deliverables/1/objectives` for the objectives index view.
|
|
65
|
+
- `/objectives/2` for an objective show view.
|
|
66
|
+
|
|
67
|
+
With Bullet Train Routes, you can simply define this as:
|
|
68
|
+
|
|
69
|
+
### ✅ Easy Example
|
|
70
|
+
```ruby
|
|
71
|
+
model "Projects::Deliverable" do
|
|
72
|
+
model "Objective"
|
|
73
|
+
end
|
|
74
|
+
````
|
|
75
|
+
|
|
76
|
+
### `Orders::Fulfillment` and `Shipping::Package` Nested Under It
|
|
77
|
+
|
|
78
|
+
If you're nesting a resource across namespaces, you'll end up with a route definition that looks like this:
|
|
79
|
+
|
|
80
|
+
### ❌ Hard Example
|
|
81
|
+
```ruby
|
|
82
|
+
namespace :orders do
|
|
83
|
+
resources :fulfillments
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
resources :orders_fulfillments, path: 'orders/fulfillments' do
|
|
87
|
+
namespace :shipping do
|
|
88
|
+
resources :packages
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
This produces the following URLs:
|
|
94
|
+
|
|
95
|
+
- `/orders/fulfillments/1` for a fulfillment show view.
|
|
96
|
+
- `/orders/fulfillments/1/shipping/packages` for the packages index view.
|
|
97
|
+
- `/shipping/packages/2` for a package show view.
|
|
98
|
+
|
|
99
|
+
With Bullet Train Routes, you can simply define this as:
|
|
100
|
+
|
|
101
|
+
### ✅ Easy Example
|
|
102
|
+
```ruby
|
|
103
|
+
model "Orders::Fulfillment" do
|
|
104
|
+
model "Shipping::Package"
|
|
105
|
+
end
|
|
106
|
+
````
|
|
107
|
+
|
|
108
|
+
## Interoperability
|
|
109
|
+
|
|
110
|
+
You can use the `model` method the same way you would the `resources` method, like so:
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
namespace :account do
|
|
114
|
+
model "Site", concerns: [:sortable] do
|
|
115
|
+
collection do
|
|
116
|
+
get :search
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
member do
|
|
120
|
+
post :publish
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Even this still works the way you'd expect.
|
|
124
|
+
resources :pages
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
```
|
|
6
128
|
|
|
7
129
|
## Installation
|
|
8
130
|
Add this line to your application's Gemfile:
|
|
@@ -16,13 +138,5 @@ And then execute:
|
|
|
16
138
|
$ bundle
|
|
17
139
|
```
|
|
18
140
|
|
|
19
|
-
Or install it yourself as:
|
|
20
|
-
```bash
|
|
21
|
-
$ gem install bullet_train-routes
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Contributing
|
|
25
|
-
Contribution directions go here.
|
|
26
|
-
|
|
27
141
|
## License
|
|
28
142
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module BulletTrain
|
|
2
|
+
module Routes
|
|
3
|
+
class Engine < ::Rails::Engine
|
|
4
|
+
# Routes are drawn by the `routes_reloader` in Rails' finisher, after every
|
|
5
|
+
# initializer has run, so installing here guarantees `model` exists in
|
|
6
|
+
# `config/routes.rb` without depending on Action Controller being loaded first.
|
|
7
|
+
initializer "bullet_train.routes.install" do
|
|
8
|
+
BulletTrain::Routes.install
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -1,109 +1,195 @@
|
|
|
1
1
|
module BulletTrain
|
|
2
2
|
module Routes
|
|
3
|
+
# Adds a `model` method to the Rails routing DSL. It's a drop-in substitute for
|
|
4
|
+
# `resources` that takes a model name instead of a resource name, and draws the
|
|
5
|
+
# shallow, namespaced routes described in the README.
|
|
6
|
+
#
|
|
7
|
+
# Every model is drawn in exactly one place:
|
|
8
|
+
#
|
|
9
|
+
# * A model with no `model` parent is drawn at its canonical location — its module
|
|
10
|
+
# path as namespaces, e.g. `model "Projects::Deliverable"` draws the same routes
|
|
11
|
+
# as `namespace :projects { resources :deliverables }`.
|
|
12
|
+
#
|
|
13
|
+
# * A model nested inside another `model` is drawn under its parent's canonical path
|
|
14
|
+
# with `shallow: true`, so its collection actions (index/new/create) nest under the
|
|
15
|
+
# parent while its member actions stay at the child's own canonical path.
|
|
16
|
+
#
|
|
17
|
+
# Rails' own `shallow:`, `shallow_path:` and `shallow_prefix:` do the splitting, so the
|
|
18
|
+
# block you pass is evaluated exactly once and every `resources` option still applies.
|
|
3
19
|
module MapperExtensions
|
|
4
|
-
|
|
5
|
-
|
|
20
|
+
# Draws routes for `name`, which can be a model name ("Projects::Deliverable"), a
|
|
21
|
+
# symbol (:project) or a model class. Accepts the same options and block as
|
|
22
|
+
# `resources`.
|
|
23
|
+
def model(name, options = nil, *extra, &block)
|
|
24
|
+
if extra.any?
|
|
25
|
+
raise ArgumentError, "`model` takes a model name and an options hash, but #{extra.count + 2} arguments were given. Did you mean `model #{name.inspect}, #{(options || {}).merge(extra.first.is_a?(Hash) ? extra.first : {}).inspect}`?"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
unless options.nil? || options.is_a?(Hash)
|
|
29
|
+
raise ArgumentError, "`model` takes an options hash as its second argument, but got #{options.inspect}. Unlike `resources`, `model` only draws one model at a time."
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# A model declared directly in another model's block is that model's child, and its
|
|
33
|
+
# member routes have to be drawn outside the parent's block to stay shallow. Record
|
|
34
|
+
# the declaration and let the parent draw it once its block closes.
|
|
35
|
+
#
|
|
36
|
+
# A model declared inside some further block (`namespace`, `scope`, `resources`…) is
|
|
37
|
+
# not deferred: we draw it where it was written, so that block still applies, exactly
|
|
38
|
+
# as it would to `resources`. Nesting it under the enclosing model shallowly would
|
|
39
|
+
# mean discarding the scope the developer opened.
|
|
40
|
+
if (pending = bullet_train_pending_models) && bullet_train_in_parent_scope?
|
|
41
|
+
pending << [name, options, block]
|
|
42
|
+
return
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
bullet_train_draw_model(bullet_train_model_segments(name), options || {}, nil, &block)
|
|
6
46
|
end
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
# Holds child `model` declarations captured while a parent's block is being evaluated.
|
|
51
|
+
# `nil` means we aren't inside a `model` block, so declarations are drawn immediately.
|
|
52
|
+
def bullet_train_pending_models
|
|
53
|
+
@bullet_train_pending_models ||= nil
|
|
10
54
|
end
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
55
|
+
|
|
56
|
+
# True when we're still in the scope the parent's block opened in, rather than inside
|
|
57
|
+
# a further block the developer opened within it. Rails replaces `@scope` for each
|
|
58
|
+
# nested block, so comparing identity is enough.
|
|
59
|
+
def bullet_train_in_parent_scope?
|
|
60
|
+
@scope.equal?(@bullet_train_block_scope ||= nil)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# "Projects::Deliverable" => ["projects", "deliverable"]
|
|
64
|
+
def bullet_train_model_segments(name)
|
|
65
|
+
string = case name
|
|
66
|
+
when String, Symbol
|
|
67
|
+
name.to_s
|
|
19
68
|
else
|
|
20
|
-
|
|
69
|
+
name.respond_to?(:name) ? name.name.to_s : ""
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
segments = string.delete_prefix("::").underscore.split("/")
|
|
73
|
+
|
|
74
|
+
if segments.empty? || segments.any?(&:empty?)
|
|
75
|
+
raise ArgumentError, "`model` couldn't make a route out of #{name.inspect}. Pass a model name like \"Projects::Deliverable\", a symbol like :deliverable, or the model class itself."
|
|
21
76
|
end
|
|
77
|
+
|
|
78
|
+
segments
|
|
22
79
|
end
|
|
23
|
-
|
|
24
|
-
def
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
80
|
+
|
|
81
|
+
def bullet_train_draw_model(segments, options, parent, &block)
|
|
82
|
+
namespaces = segments[0..-2]
|
|
83
|
+
collection = segments.last.pluralize.to_sym
|
|
84
|
+
|
|
85
|
+
# Children declared inside `block` are collected here and drawn after the block
|
|
86
|
+
# closes, so their member routes land outside this model's `resources` block.
|
|
87
|
+
children = []
|
|
88
|
+
resource_block = proc do
|
|
89
|
+
outer_pending, outer_scope = bullet_train_pending_models, @bullet_train_block_scope
|
|
90
|
+
@bullet_train_pending_models = children
|
|
91
|
+
@bullet_train_block_scope = @scope
|
|
92
|
+
|
|
93
|
+
begin
|
|
94
|
+
block&.call
|
|
95
|
+
ensure
|
|
96
|
+
@bullet_train_pending_models = outer_pending
|
|
97
|
+
@bullet_train_block_scope = outer_scope
|
|
32
98
|
end
|
|
33
99
|
end
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
parent_namespace_names.shift
|
|
100
|
+
|
|
101
|
+
if parent
|
|
102
|
+
bullet_train_draw_nested(namespaces, collection, options, parent, &resource_block)
|
|
103
|
+
else
|
|
104
|
+
bullet_train_namespaces(namespaces) do
|
|
105
|
+
resources collection, **options, &resource_block
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
return if children.empty?
|
|
110
|
+
|
|
111
|
+
me = {namespaces: namespaces, collection: collection, options: options}
|
|
112
|
+
children.each do |(child_name, child_options, child_block)|
|
|
113
|
+
bullet_train_draw_model(bullet_train_model_segments(child_name), child_options || {}, me, &child_block)
|
|
49
114
|
end
|
|
50
|
-
|
|
51
|
-
parent_namespace_names
|
|
52
115
|
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
namespace current_namespaces_last.to_sym do
|
|
78
|
-
resources model_name.pluralize.to_sym, (parameters[1] || {}).merge(except: [:index, :new, :create]), &block
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
current_namespaces.pop[:pending_blocks].each do |block|
|
|
83
|
-
block.call
|
|
84
|
-
end
|
|
85
|
-
# E.g. `Projects::Deliverable` and `Objective`
|
|
86
|
-
elsif (ejection_count = namespaces_to_eject(original_namespace_names).count) > 0
|
|
87
|
-
resource_symbol = current_models[-2][:model_name][((ejection_count + 1) * -1)..-1].join("_").to_sym
|
|
88
|
-
resource_path = current_models[-2][:model_name][((ejection_count + 1) * -1)..-1].join("/")
|
|
89
|
-
|
|
90
|
-
current_namespaces[ejection_count * -1][:pending_blocks] << proc do
|
|
91
|
-
resources resource_symbol, path: resource_path do
|
|
92
|
-
namespaces namespace_names do
|
|
93
|
-
resources model_name.pluralize.to_sym, parameters[1] || {}, &block
|
|
116
|
+
|
|
117
|
+
# Draws a child model under its parent's canonical path. The parent is reopened with
|
|
118
|
+
# `only: []` so nesting adds no duplicate routes of its own.
|
|
119
|
+
def bullet_train_draw_nested(namespaces, collection, options, parent, &resource_block)
|
|
120
|
+
# Namespaces the parent and child share are drawn as real namespaces, so names and
|
|
121
|
+
# params read the way the hand-written Rails equivalent would.
|
|
122
|
+
# E.g. `Hosting::Site` + `Hosting::Page` nest under `:site_id`, not `:hosting_site_id`.
|
|
123
|
+
shared = bullet_train_common_prefix(parent[:namespaces], namespaces)
|
|
124
|
+
parent_segments = parent[:namespaces][shared.size..] + [parent[:collection].to_s]
|
|
125
|
+
child_segments = namespaces[shared.size..]
|
|
126
|
+
|
|
127
|
+
# Leading child namespaces the parent's own path already spells out contribute the
|
|
128
|
+
# child's module and shallow path, but must not be repeated in the nested path.
|
|
129
|
+
# E.g. `Project` + `Projects::Deliverable` nest at `/projects/:project_id/deliverables`.
|
|
130
|
+
implied = bullet_train_common_prefix(parent_segments, child_segments)
|
|
131
|
+
nested = child_segments[implied.size..]
|
|
132
|
+
|
|
133
|
+
nesting_name, nesting_options = bullet_train_nesting_arguments(parent_segments, parent[:options])
|
|
134
|
+
|
|
135
|
+
bullet_train_namespaces(shared) do
|
|
136
|
+
resources nesting_name, **nesting_options do
|
|
137
|
+
bullet_train_implied_scope(implied) do
|
|
138
|
+
bullet_train_namespaces(nested) do
|
|
139
|
+
resources collection, shallow: true, **options, &resource_block
|
|
94
140
|
end
|
|
95
141
|
end
|
|
96
142
|
end
|
|
97
|
-
else
|
|
98
|
-
namespaces namespace_names do
|
|
99
|
-
resources model_name.pluralize.to_sym, parameters[1] || {}, &block
|
|
100
|
-
end
|
|
101
143
|
end
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Reopens the parent resource purely as a place to nest. Only the options that decide
|
|
147
|
+
# the child's URL shape are carried over; the parent's own routes were already drawn.
|
|
148
|
+
def bullet_train_nesting_arguments(parent_segments, parent_options)
|
|
149
|
+
leading = parent_segments[0..-2]
|
|
150
|
+
last = parent_segments.last
|
|
151
|
+
|
|
152
|
+
path = leading + [parent_options[:path]&.to_s || last]
|
|
153
|
+
# `shallow: false` keeps an ambient `shallow` scope — e.g. a `shallow do` block around the
|
|
154
|
+
# whole route file — from applying Rails' shallow path to the nesting itself, which would
|
|
155
|
+
# prepend the child's shallow path to its nested path a second time. The child re-enables
|
|
156
|
+
# `shallow` for its own routes.
|
|
157
|
+
options = {path: path.join("/"), only: [], shallow: false}
|
|
158
|
+
options[:param] = parent_options[:param] if parent_options[:param]
|
|
159
|
+
options[:as] = (leading + [parent_options[:as].to_s]).join("_") if parent_options[:as]
|
|
160
|
+
|
|
161
|
+
[parent_segments.join("_").to_sym, options]
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def bullet_train_implied_scope(implied, &block)
|
|
165
|
+
return yield if implied.empty?
|
|
166
|
+
|
|
167
|
+
scope(
|
|
168
|
+
module: implied.join("/"),
|
|
169
|
+
shallow_path: implied.join("/"),
|
|
170
|
+
shallow_prefix: implied.join("_"),
|
|
171
|
+
&block
|
|
172
|
+
)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def bullet_train_namespaces(names, &block)
|
|
176
|
+
return yield if names.empty?
|
|
177
|
+
|
|
178
|
+
namespace names.first do
|
|
179
|
+
bullet_train_namespaces(names[1..], &block)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def bullet_train_common_prefix(first, second)
|
|
184
|
+
prefix = []
|
|
185
|
+
|
|
186
|
+
first.each_with_index do |segment, index|
|
|
187
|
+
break unless second[index] == segment
|
|
188
|
+
prefix << segment
|
|
105
189
|
end
|
|
190
|
+
|
|
191
|
+
prefix
|
|
106
192
|
end
|
|
107
193
|
end
|
|
108
194
|
end
|
|
109
|
-
end
|
|
195
|
+
end
|
data/lib/bullet_train/routes.rb
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
require "bullet_train/routes/version"
|
|
2
|
-
require "bullet_train/routes/railtie"
|
|
3
2
|
require "bullet_train/routes/mapper_extensions"
|
|
4
3
|
|
|
5
4
|
module BulletTrain
|
|
6
5
|
module Routes
|
|
6
|
+
# Makes `model` available in the routing DSL. Safe to call more than once.
|
|
7
|
+
def self.install
|
|
8
|
+
return false unless defined?(ActionDispatch::Routing::Mapper)
|
|
9
|
+
return false if ActionDispatch::Routing::Mapper.include?(MapperExtensions)
|
|
10
|
+
|
|
11
|
+
ActionDispatch::Routing::Mapper.include(MapperExtensions)
|
|
12
|
+
true
|
|
13
|
+
end
|
|
7
14
|
end
|
|
8
15
|
end
|
|
9
16
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
# In a Rails app the engine installs the DSL from an initializer, which always runs before
|
|
18
|
+
# `config/routes.rb` is evaluated. Outside Rails (or if Action Pack is already loaded by the
|
|
19
|
+
# time this file is required) install it right away.
|
|
20
|
+
if defined?(Rails::Engine)
|
|
21
|
+
require "bullet_train/routes/engine"
|
|
22
|
+
else
|
|
23
|
+
BulletTrain::Routes.install
|
|
24
|
+
end
|
metadata
CHANGED
|
@@ -1,29 +1,56 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bullet_train-routes
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.46.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Culver
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: standard
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: simplecov
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
13
40
|
- !ruby/object:Gem::Dependency
|
|
14
41
|
name: rails
|
|
15
42
|
requirement: !ruby/object:Gem::Requirement
|
|
16
43
|
requirements:
|
|
17
44
|
- - ">="
|
|
18
45
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
46
|
+
version: 7.0.0
|
|
20
47
|
type: :runtime
|
|
21
48
|
prerelease: false
|
|
22
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
50
|
requirements:
|
|
24
51
|
- - ">="
|
|
25
52
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
53
|
+
version: 7.0.0
|
|
27
54
|
description: Black magic for defining model-driven routes.
|
|
28
55
|
email:
|
|
29
56
|
- andrew.culver@gmail.com
|
|
@@ -35,17 +62,16 @@ files:
|
|
|
35
62
|
- README.md
|
|
36
63
|
- Rakefile
|
|
37
64
|
- lib/bullet_train/routes.rb
|
|
65
|
+
- lib/bullet_train/routes/engine.rb
|
|
38
66
|
- lib/bullet_train/routes/mapper_extensions.rb
|
|
39
|
-
- lib/bullet_train/routes/railtie.rb
|
|
40
67
|
- lib/bullet_train/routes/version.rb
|
|
41
68
|
- lib/tasks/bullet_train/routes_tasks.rake
|
|
42
|
-
homepage: https://github.com/bullet-train-co/bullet_train-routes
|
|
69
|
+
homepage: https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-routes
|
|
43
70
|
licenses:
|
|
44
71
|
- MIT
|
|
45
72
|
metadata:
|
|
46
|
-
homepage_uri: https://github.com/bullet-train-co/bullet_train-routes
|
|
47
|
-
source_code_uri: https://github.com/bullet-train-co/bullet_train-routes
|
|
48
|
-
post_install_message:
|
|
73
|
+
homepage_uri: https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-routes
|
|
74
|
+
source_code_uri: https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-routes
|
|
49
75
|
rdoc_options: []
|
|
50
76
|
require_paths:
|
|
51
77
|
- lib
|
|
@@ -60,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
60
86
|
- !ruby/object:Gem::Version
|
|
61
87
|
version: '0'
|
|
62
88
|
requirements: []
|
|
63
|
-
rubygems_version:
|
|
64
|
-
signing_key:
|
|
89
|
+
rubygems_version: 4.0.6
|
|
65
90
|
specification_version: 4
|
|
66
91
|
summary: Bullet Train Routes
|
|
67
92
|
test_files: []
|