much-rails 0.1.0 → 0.1.1
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/lib/much-rails/action/base_router.rb +33 -13
- data/lib/much-rails/action/controller.rb +17 -2
- data/lib/much-rails/action/router.rb +10 -2
- data/lib/much-rails/version.rb +1 -1
- data/much-rails.gemspec +1 -1
- data/test/support/fake_action_controller.rb +1 -1
- data/test/unit/action/base_router_tests.rb +13 -10
- data/test/unit/action/controller_tests.rb +6 -1
- data/test/unit/action/router_tests.rb +23 -7
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0172aa43ad656d16da5f3becf0dc3792488c920453799ab14d69281a6db8799c
|
4
|
+
data.tar.gz: e7e6d23911c2525703639b38d5f2f8974d048e4c953ddb9b8bd77e37aacbdcdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897a07060cecba2fab179514b8aa1d116a51bef41477486dc9ca0e10a63e0cfaaf75680a2b99bcad1aa36e7670d5b5e3f678cb97a4f2bf004da0303cf918c9b5
|
7
|
+
data.tar.gz: ad74dbf2040de64bb85d70c89f5729635cb947ab9d6efb38dfa8249a109097c3416a08e5923dde311edf8c07373cde3e0af7502166d5449c393d973f588e09b2
|
@@ -19,6 +19,7 @@ class MuchRails::Action::BaseRouter
|
|
19
19
|
@request_type_set = RequestTypeSet.new
|
20
20
|
@url_set = URLSet.new(self)
|
21
21
|
@definitions = []
|
22
|
+
@defined_urls = []
|
22
23
|
|
23
24
|
@base_url = DEFAULT_BASE_URL
|
24
25
|
instance_exec(&(block || proc{}))
|
@@ -28,6 +29,10 @@ class MuchRails::Action::BaseRouter
|
|
28
29
|
self.class.url_class
|
29
30
|
end
|
30
31
|
|
32
|
+
def unrouted_urls
|
33
|
+
@url_set.urls - @defined_urls
|
34
|
+
end
|
35
|
+
|
31
36
|
def validate!
|
32
37
|
definitions.each do |definition|
|
33
38
|
definition.request_type_actions.each do |request_type_action|
|
@@ -240,15 +245,22 @@ class MuchRails::Action::BaseRouter
|
|
240
245
|
acc
|
241
246
|
end
|
242
247
|
|
243
|
-
|
244
|
-
.for_route(
|
248
|
+
add_definition(
|
249
|
+
Definition.for_route(
|
245
250
|
http_method: http_method,
|
246
251
|
url: url,
|
247
252
|
default_action_class_name: default_class_name,
|
248
253
|
request_type_actions: request_type_actions,
|
249
254
|
called_from: called_from,
|
250
|
-
)
|
251
|
-
|
255
|
+
),
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
def add_definition(definition)
|
260
|
+
@definitions << definition
|
261
|
+
@defined_urls << definition.url
|
262
|
+
|
263
|
+
definition
|
252
264
|
end
|
253
265
|
|
254
266
|
class RequestTypeSet
|
@@ -301,6 +313,10 @@ class MuchRails::Action::BaseRouter
|
|
301
313
|
@set.empty?
|
302
314
|
end
|
303
315
|
|
316
|
+
def urls
|
317
|
+
@set.values
|
318
|
+
end
|
319
|
+
|
304
320
|
def add(name, path)
|
305
321
|
url = @router.url_class.new(@router, path, name.to_sym)
|
306
322
|
key = url.name
|
@@ -406,35 +422,40 @@ class MuchRails::Action::BaseRouter
|
|
406
422
|
called_from:)
|
407
423
|
new(
|
408
424
|
http_method: http_method,
|
409
|
-
|
410
|
-
name: url.name,
|
425
|
+
url: url,
|
411
426
|
default_action_class_name: default_action_class_name,
|
412
427
|
request_type_actions: request_type_actions,
|
413
428
|
called_from: called_from,
|
414
429
|
)
|
415
430
|
end
|
416
431
|
|
417
|
-
attr_reader :http_method, :
|
432
|
+
attr_reader :http_method, :url, :default_params
|
418
433
|
attr_reader :default_action_class_name, :request_type_actions
|
419
434
|
attr_reader :called_from
|
420
435
|
|
421
436
|
def initialize(
|
422
437
|
http_method:,
|
423
|
-
|
424
|
-
name:,
|
438
|
+
url:,
|
425
439
|
default_action_class_name:,
|
426
440
|
request_type_actions:,
|
427
441
|
called_from:,
|
428
442
|
default_params: nil)
|
429
443
|
@http_method = http_method
|
430
|
-
@
|
431
|
-
@name = name
|
444
|
+
@url = url
|
432
445
|
@default_params = default_params || {}
|
433
446
|
@default_action_class_name = default_action_class_name
|
434
447
|
@request_type_actions = request_type_actions || []
|
435
448
|
@called_from = called_from
|
436
449
|
end
|
437
450
|
|
451
|
+
def name
|
452
|
+
@url.name
|
453
|
+
end
|
454
|
+
|
455
|
+
def path
|
456
|
+
@url.path
|
457
|
+
end
|
458
|
+
|
438
459
|
def has_default_action_class_name?
|
439
460
|
!@default_action_class_name.nil?
|
440
461
|
end
|
@@ -443,8 +464,7 @@ class MuchRails::Action::BaseRouter
|
|
443
464
|
return super unless other.is_a?(self.class)
|
444
465
|
|
445
466
|
@http_method == other.http_method &&
|
446
|
-
@
|
447
|
-
@name == other.name &&
|
467
|
+
@url == other.url &&
|
448
468
|
@default_params == other.default_params &&
|
449
469
|
@default_action_class_name ==
|
450
470
|
other.default_action_class_name &&
|
@@ -14,12 +14,17 @@ module MuchRails::Action::Controller
|
|
14
14
|
mixin_included do
|
15
15
|
attr_reader :much_rails_action_class
|
16
16
|
|
17
|
-
before_action
|
17
|
+
before_action(
|
18
|
+
:require_much_rails_action_class,
|
19
|
+
only: MuchRails::Action::Router::CONTROLLER_CALL_ACTION_METHOD_NAME,
|
20
|
+
)
|
18
21
|
before_action :permit_all_much_rails_action_params
|
19
22
|
end
|
20
23
|
|
21
24
|
mixin_instance_methods do
|
22
|
-
define_method(
|
25
|
+
define_method(
|
26
|
+
MuchRails::Action::Router::CONTROLLER_CALL_ACTION_METHOD_NAME,
|
27
|
+
) do
|
23
28
|
respond_to do |format|
|
24
29
|
format.public_send(much_rails_action_class.format) do
|
25
30
|
result =
|
@@ -33,6 +38,16 @@ module MuchRails::Action::Controller
|
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
41
|
+
define_method(
|
42
|
+
MuchRails::Action::Router::CONTROLLER_NOT_FOUND_METHOD_NAME,
|
43
|
+
) do
|
44
|
+
respond_to do |format|
|
45
|
+
format.html do
|
46
|
+
head :not_found
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
36
51
|
def much_rails_action_class_name
|
37
52
|
"::#{params[MuchRails::Action::Router::ACTION_CLASS_PARAM_NAME]}"
|
38
53
|
end
|
@@ -7,7 +7,8 @@ module MuchRails::Action; end
|
|
7
7
|
|
8
8
|
class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
9
9
|
DEFAULT_CONTROLLER_NAME = "application"
|
10
|
-
|
10
|
+
CONTROLLER_CALL_ACTION_METHOD_NAME = :much_rails_call_action
|
11
|
+
CONTROLLER_NOT_FOUND_METHOD_NAME = :much_rails_not_found
|
11
12
|
ACTION_CLASS_PARAM_NAME = :much_rails_action_class_name
|
12
13
|
|
13
14
|
def self.url_class
|
@@ -48,7 +49,8 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
|
48
49
|
# end
|
49
50
|
def apply_to(application_routes_draw_scope)
|
50
51
|
validate!
|
51
|
-
|
52
|
+
draw_url_to = "#{controller_name}##{CONTROLLER_NOT_FOUND_METHOD_NAME}"
|
53
|
+
draw_route_to = "#{controller_name}##{CONTROLLER_CALL_ACTION_METHOD_NAME}"
|
52
54
|
|
53
55
|
definitions.each do |definition|
|
54
56
|
definition.request_type_actions.each do |request_type_action|
|
@@ -78,6 +80,12 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
|
78
80
|
}),
|
79
81
|
)
|
80
82
|
end
|
83
|
+
|
84
|
+
# Draw each URL that doesn't have a route definition so that we can generate
|
85
|
+
# them using MuchRails::RailsRoutes.
|
86
|
+
unrouted_urls.each do |url|
|
87
|
+
application_routes_draw_scope.get(url.path, to: draw_url_to, as: url.name)
|
88
|
+
end
|
81
89
|
end
|
82
90
|
alias_method :draw, :apply_to
|
83
91
|
|
data/lib/much-rails/version.rb
CHANGED
data/much-rails.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.required_ruby_version = "~> 2.5"
|
25
25
|
|
26
26
|
gem.add_development_dependency("much-style-guide", ["~> 0.6.0"])
|
27
|
-
gem.add_development_dependency("assert", ["~> 2.19.
|
27
|
+
gem.add_development_dependency("assert", ["~> 2.19.5"])
|
28
28
|
gem.add_development_dependency("rails", ["> 5.0", "< 7.0"])
|
29
29
|
|
30
30
|
gem.add_dependency("activerecord", ["> 5.0", "< 7.0"])
|
@@ -52,7 +52,7 @@ class MuchRails::Action::BaseRouter
|
|
52
52
|
should have_readers :name
|
53
53
|
should have_readers :request_type_set, :url_set, :definitions
|
54
54
|
|
55
|
-
should have_imeths :url_class, :apply_to
|
55
|
+
should have_imeths :url_class, :unrouted_urls, :apply_to
|
56
56
|
should have_imeths :path_for, :url_for
|
57
57
|
should have_imeths :request_type
|
58
58
|
should have_imeths :base_url, :url
|
@@ -62,6 +62,7 @@ class MuchRails::Action::BaseRouter
|
|
62
62
|
assert_that(subject.name).is_nil
|
63
63
|
assert_that(subject.request_type_set).is_empty
|
64
64
|
assert_that(subject.url_set).is_empty
|
65
|
+
assert_that(subject.unrouted_urls).is_empty
|
65
66
|
assert_that(subject.definitions).is_empty
|
66
67
|
assert_that(subject.base_url).equals(unit_class::DEFAULT_BASE_URL)
|
67
68
|
assert_that(subject.url_class).equals(unit_class.url_class)
|
@@ -106,6 +107,7 @@ class MuchRails::Action::BaseRouter
|
|
106
107
|
assert_that(subject.url_set).is_not_empty
|
107
108
|
assert_that(url).is_kind_of(subject.url_class)
|
108
109
|
assert_that(@url_set_add_call.args).equals([:url1, path])
|
110
|
+
assert_that(subject.unrouted_urls).equals([url])
|
109
111
|
|
110
112
|
ex =
|
111
113
|
assert_that{ subject.url(:url2.to_s, Factory.url) }
|
@@ -338,13 +340,14 @@ class MuchRails::Action::BaseRouter
|
|
338
340
|
|
339
341
|
let(:router1){ unit_class.new }
|
340
342
|
|
341
|
-
should have_imeths :empty?, :add, :fetch, :path_for, :url_for
|
343
|
+
should have_imeths :empty?, :urls, :add, :fetch, :path_for, :url_for
|
342
344
|
|
343
345
|
should "add URLs" do
|
344
346
|
assert_that(subject).is_empty
|
345
347
|
|
346
348
|
url = subject.add(:url1.to_s, path = Factory.url)
|
347
349
|
assert_that(subject).is_not_empty
|
350
|
+
assert_that(subject.urls).equals([url])
|
348
351
|
assert_that(url).is_kind_of(router1.url_class)
|
349
352
|
assert_that(@url_new_call.args).equals([router1, path, :url1])
|
350
353
|
|
@@ -472,8 +475,7 @@ class MuchRails::Action::BaseRouter
|
|
472
475
|
definition1 =
|
473
476
|
definition_class.new(
|
474
477
|
http_method: http_method1,
|
475
|
-
|
476
|
-
name: url_name1,
|
478
|
+
url: url1,
|
477
479
|
default_action_class_name: default_action_class_name1,
|
478
480
|
request_type_actions: request_type_actions1,
|
479
481
|
called_from: caller1,
|
@@ -496,8 +498,7 @@ class MuchRails::Action::BaseRouter
|
|
496
498
|
subject do
|
497
499
|
definition_class.new(
|
498
500
|
http_method: http_method1,
|
499
|
-
|
500
|
-
name: url_name1,
|
501
|
+
url: url1,
|
501
502
|
default_action_class_name: default_action_class_name1,
|
502
503
|
request_type_actions: request_type_actions1,
|
503
504
|
default_params: default_params1,
|
@@ -509,19 +510,21 @@ class MuchRails::Action::BaseRouter
|
|
509
510
|
{ Factory.string => Factory.string }
|
510
511
|
end
|
511
512
|
|
512
|
-
should have_readers :http_method, :
|
513
|
+
should have_readers :http_method, :url, :default_params
|
513
514
|
should have_readers :default_action_class_name, :request_type_actions
|
514
|
-
should
|
515
|
+
should have_readers :called_from
|
516
|
+
should have_imeths :path, :name, :has_default_action_class_name?
|
515
517
|
|
516
518
|
should "know its attributes" do
|
517
519
|
assert_that(subject.http_method).equals(http_method1)
|
518
|
-
assert_that(subject.
|
519
|
-
assert_that(subject.name).equals(url_name1)
|
520
|
+
assert_that(subject.url).equals(url1)
|
520
521
|
assert_that(subject.default_params).equals(default_params1)
|
521
522
|
assert_that(subject.default_action_class_name)
|
522
523
|
.equals(default_action_class_name1)
|
523
524
|
assert_that(subject.request_type_actions).equals(request_type_actions1)
|
524
525
|
assert_that(subject.called_from).equals(caller1)
|
526
|
+
assert_that(subject.path).equals(url_path1)
|
527
|
+
assert_that(subject.name).equals(url_name1)
|
525
528
|
end
|
526
529
|
end
|
527
530
|
end
|
@@ -44,7 +44,12 @@ module MuchRails::Action::Controller
|
|
44
44
|
|
45
45
|
should have_readers :much_rails_action_class
|
46
46
|
|
47
|
-
should have_imeths
|
47
|
+
should have_imeths(
|
48
|
+
MuchRails::Action::Router::CONTROLLER_CALL_ACTION_METHOD_NAME,
|
49
|
+
)
|
50
|
+
should have_imeths(
|
51
|
+
MuchRails::Action::Router::CONTROLLER_NOT_FOUND_METHOD_NAME,
|
52
|
+
)
|
48
53
|
should have_imeths :much_rails_action_class_name
|
49
54
|
should have_imeths :much_rails_action_params
|
50
55
|
should have_imeths :require_much_rails_action_class
|
@@ -22,8 +22,10 @@ class MuchRails::Action::Router
|
|
22
22
|
|
23
23
|
should "know its constants" do
|
24
24
|
assert_that(subject::DEFAULT_CONTROLLER_NAME).equals("application")
|
25
|
-
assert_that(subject::
|
25
|
+
assert_that(subject::CONTROLLER_CALL_ACTION_METHOD_NAME)
|
26
26
|
.equals(:much_rails_call_action)
|
27
|
+
assert_that(subject::CONTROLLER_NOT_FOUND_METHOD_NAME)
|
28
|
+
.equals(:much_rails_not_found)
|
27
29
|
assert_that(subject::ACTION_CLASS_PARAM_NAME)
|
28
30
|
.equals(:much_rails_action_class_name)
|
29
31
|
assert_that(subject.url_class).equals(unit_class::URL)
|
@@ -88,17 +90,25 @@ class MuchRails::Action::Router
|
|
88
90
|
subject.patch(url_name, default_class_name)
|
89
91
|
subject.delete(url_name, default_class_name)
|
90
92
|
|
93
|
+
url2_name = Factory.symbol
|
94
|
+
url2_path = Factory.url
|
95
|
+
subject.url(url2_name, url2_path)
|
96
|
+
|
91
97
|
application_routes = FakeApplicationRoutes.new
|
92
98
|
subject.draw(application_routes)
|
93
99
|
|
100
|
+
expected_draw_url_to =
|
101
|
+
"#{subject.controller_name}"\
|
102
|
+
"##{unit_class::CONTROLLER_NOT_FOUND_METHOD_NAME}"
|
94
103
|
expected_draw_route_to =
|
95
|
-
"#{subject.controller_name}
|
104
|
+
"#{subject.controller_name}"\
|
105
|
+
"##{unit_class::CONTROLLER_CALL_ACTION_METHOD_NAME}"
|
96
106
|
expected_default_defaults =
|
97
107
|
{ unit_class::ACTION_CLASS_PARAM_NAME => default_class_name }
|
98
108
|
|
99
|
-
assert_that(application_routes.get_calls.size).equals(
|
100
|
-
assert_that(application_routes.get_calls.
|
101
|
-
assert_that(application_routes.get_calls.
|
109
|
+
assert_that(application_routes.get_calls.size).equals(3)
|
110
|
+
assert_that(application_routes.get_calls[0].pargs).equals([url_path])
|
111
|
+
assert_that(application_routes.get_calls[0].kargs)
|
102
112
|
.equals(
|
103
113
|
to: expected_draw_route_to,
|
104
114
|
as: url_name,
|
@@ -106,13 +116,19 @@ class MuchRails::Action::Router
|
|
106
116
|
{ unit_class::ACTION_CLASS_PARAM_NAME => request_type_class_name },
|
107
117
|
constraints: request_type_proc,
|
108
118
|
)
|
109
|
-
assert_that(application_routes.get_calls.
|
110
|
-
assert_that(application_routes.get_calls.
|
119
|
+
assert_that(application_routes.get_calls[1].pargs).equals([url_path])
|
120
|
+
assert_that(application_routes.get_calls[1].kargs)
|
111
121
|
.equals(
|
112
122
|
to: expected_draw_route_to,
|
113
123
|
as: url_name,
|
114
124
|
defaults: expected_default_defaults,
|
115
125
|
)
|
126
|
+
assert_that(application_routes.get_calls[2].pargs).equals([url2_path])
|
127
|
+
assert_that(application_routes.get_calls[2].kargs)
|
128
|
+
.equals(
|
129
|
+
to: expected_draw_url_to,
|
130
|
+
as: url2_name,
|
131
|
+
)
|
116
132
|
|
117
133
|
assert_that(application_routes.post_calls.size).equals(1)
|
118
134
|
assert_that(application_routes.post_calls.last.pargs).equals([url_path])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-01-
|
12
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: much-style-guide
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.19.
|
34
|
+
version: 2.19.5
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 2.19.
|
41
|
+
version: 2.19.5
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rails
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|