inferred_crumpets 0.2.3 → 0.2.4

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
  SHA1:
3
- metadata.gz: 2e49994914324e9b9564161b3713f75ebc20d329
4
- data.tar.gz: acf2a10fe6b04e4298f7478d55528cf69c7a3476
3
+ metadata.gz: 6250044ac0ab2d1597b36ba4475f8ba7efe47cc2
4
+ data.tar.gz: f14abcedf89bd9e396dafe8481d9ee0217dc615f
5
5
  SHA512:
6
- metadata.gz: d10b75694952f205811c04ce3613f67676739cad37952035f7adbbc2f51442bc4764b503c6a1fbf07ebc01ede390ebe240a7f71d4b4fed358bb0a35ae8593eda
7
- data.tar.gz: b90189c270066f977b842b2664de1ecb3a19ad631a6a2a482a9bc0f77431f99292adfc0020e4c5be06993871a2996f253da5fc6db28fc1c64eecd1be3396659b
6
+ metadata.gz: ccd76c2a344cb2932ab1214a21e8652ee2a9118751ed36d849eebf5b99608b19d8ec35a93f920a9131ea0830c533ea54a2c2fcf2bbd7b602c266f4da107f30dd
7
+ data.tar.gz: 867545fa1b70b5486ea715ec8872aa556ea4f6920550323a06a795d9249d0faf0782c70d78060dffc9df6bc01209bf32f74aed436fa3b1f4141f2f314df315b4
data/.gitignore CHANGED
@@ -7,6 +7,8 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /vendor/
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
14
+ *.gem
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # InferredCrumpets
2
2
 
3
+ ## 0.2.4
4
+
5
+ * [TT-3102] Move url checking out into seperate class
6
+ * [TT-3102] Fix regression where subject routes where not build properly
7
+
3
8
  ## 0.2.3
4
9
 
5
10
  * [TT-3117] Fix: NoMethodError when subject is not linkable
@@ -1,3 +1,4 @@
1
+ require "inferred_crumpets/route_checker"
1
2
  require "inferred_crumpets/builder"
2
3
  require "inferred_crumpets/railtie"
3
4
  require "inferred_crumpets/version"
@@ -18,9 +18,10 @@ module InferredCrumpets
18
18
  end
19
19
 
20
20
  def initialize(view_context, subject, parents = [])
21
- @view_context = view_context
22
- @subject = subject
23
- @parents = parents
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? && shallow?
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(shallow? ? transformed_subject : subject_with_parents)
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(shallow? ? transformed_subject.class : class_with_parents)
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) && view_context.url_for((parents + [subject.class]).compact).blank?
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 shallow?
94
- view_context.url_for(transformed_subject)
95
- rescue NoMethodError
96
- false
93
+ def linkable?
94
+ @route_checker.linkable?(transformed_subject)
97
95
  end
98
96
 
99
- def linkable?
100
- view_context.url_for(subject)
101
- rescue NoMethodError
102
- false
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
- view_context.url_for({
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
@@ -1,3 +1,3 @@
1
1
  module InferredCrumpets
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  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.3
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-08-31 00:00:00.000000000 Z
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