inferred_crumpets 0.2.3 → 0.2.4
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/.gitignore +2 -0
- data/CHANGELOG.md +5 -0
- data/lib/inferred_crumpets.rb +1 -0
- data/lib/inferred_crumpets/builder.rb +18 -27
- data/lib/inferred_crumpets/route_checker.rb +22 -0
- data/lib/inferred_crumpets/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6250044ac0ab2d1597b36ba4475f8ba7efe47cc2
|
4
|
+
data.tar.gz: f14abcedf89bd9e396dafe8481d9ee0217dc615f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccd76c2a344cb2932ab1214a21e8652ee2a9118751ed36d849eebf5b99608b19d8ec35a93f920a9131ea0830c533ea54a2c2fcf2bbd7b602c266f4da107f30dd
|
7
|
+
data.tar.gz: 867545fa1b70b5486ea715ec8872aa556ea4f6920550323a06a795d9249d0faf0782c70d78060dffc9df6bc01209bf32f74aed436fa3b1f4141f2f314df315b4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/inferred_crumpets.rb
CHANGED
@@ -18,9 +18,10 @@ module InferredCrumpets
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize(view_context, subject, parents = [])
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
21
|
+
@route_checker = RouteChecker.new(view_context)
|
22
|
+
@view_context = view_context
|
23
|
+
@subject = subject
|
24
|
+
@parents = parents
|
24
25
|
end
|
25
26
|
|
26
27
|
def build_all!
|
@@ -42,7 +43,7 @@ module InferredCrumpets
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def build_crumb_for_collection!
|
45
|
-
return if parents.present? &&
|
46
|
+
return if parents.present? && linkable?
|
46
47
|
|
47
48
|
if subject.is_a?(ActiveRecord::Relation)
|
48
49
|
view_context.crumbs.add_crumb subject_name.pluralize.titleize
|
@@ -71,44 +72,38 @@ module InferredCrumpets
|
|
71
72
|
|
72
73
|
def url_for_subject
|
73
74
|
return unless can_route?(:show, id: subject.id) && linkable?
|
74
|
-
view_context.url_for(
|
75
|
+
view_context.url_for(transformed_subject)
|
75
76
|
end
|
76
77
|
|
77
78
|
def url_for_collection
|
78
79
|
return view_context.objects_path if view_context.objects_path.present?
|
79
80
|
return unless can_route?(:index)
|
80
|
-
view_context.url_for(
|
81
|
+
return view_context.url_for(transformed_subject.class) if linkable?
|
82
|
+
return view_context.url_for(class_with_parents) if parents_and_class_linkable?
|
81
83
|
end
|
82
84
|
|
83
85
|
def subject_requires_transformation?
|
84
|
-
subject.respond_to?(:becomes) &&
|
85
|
-
rescue NoMethodError
|
86
|
-
true
|
86
|
+
subject.respond_to?(:becomes) && !parents_and_subject_linkable?
|
87
87
|
end
|
88
88
|
|
89
89
|
def transformed_subject
|
90
90
|
subject_requires_transformation? ? subject.becomes(subject.class.base_class) : subject
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
94
|
-
|
95
|
-
rescue NoMethodError
|
96
|
-
false
|
93
|
+
def linkable?
|
94
|
+
@route_checker.linkable?(transformed_subject)
|
97
95
|
end
|
98
96
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
def parents_and_subject_linkable?
|
98
|
+
@route_checker.linkable?((parents + [subject.class]).compact)
|
99
|
+
end
|
100
|
+
|
101
|
+
def parents_and_class_linkable?
|
102
|
+
@route_checker.linkable?((parents + [transformed_subject.class]).compact)
|
103
103
|
end
|
104
104
|
|
105
105
|
def can_route?(action, params = {})
|
106
|
-
|
107
|
-
action: action,
|
108
|
-
controller: subject.class.table_name,
|
109
|
-
}.merge(params))
|
110
|
-
rescue ActionController::RoutingError
|
111
|
-
false
|
106
|
+
@route_checker.can_route?(subject, action, params)
|
112
107
|
end
|
113
108
|
|
114
109
|
def action
|
@@ -123,10 +118,6 @@ module InferredCrumpets
|
|
123
118
|
(parents + [transformed_subject.class]).compact
|
124
119
|
end
|
125
120
|
|
126
|
-
def subject_with_parents
|
127
|
-
(parents + [transformed_subject]).compact
|
128
|
-
end
|
129
|
-
|
130
121
|
def inherited_resources?
|
131
122
|
defined?(InheritedResources) && view_context.controller.responder == InheritedResources::Responder
|
132
123
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module InferredCrumpets
|
2
|
+
class RouteChecker
|
3
|
+
def initialize(view_context)
|
4
|
+
@view_context = view_context
|
5
|
+
end
|
6
|
+
|
7
|
+
def linkable?(subject)
|
8
|
+
@view_context.url_for(subject) && true
|
9
|
+
rescue NoMethodError
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def can_route?(subject, action, params = {})
|
14
|
+
@view_context.url_for({
|
15
|
+
action: action,
|
16
|
+
controller: subject.class.table_name,
|
17
|
+
}.merge(params))
|
18
|
+
rescue ActionController::RoutingError
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inferred_crumpets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Colegate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/inferred_crumpets.rb
|
104
104
|
- lib/inferred_crumpets/builder.rb
|
105
105
|
- lib/inferred_crumpets/railtie.rb
|
106
|
+
- lib/inferred_crumpets/route_checker.rb
|
106
107
|
- lib/inferred_crumpets/version.rb
|
107
108
|
- lib/inferred_crumpets/view_helpers.rb
|
108
109
|
homepage: https://github.com/sealink/inferred_crumpets
|