brainstem 1.4.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0942f85fafa0e040a4fdc07a3d61d8e09a5fe0f7'
4
- data.tar.gz: f6f6d59618aefc3d545e8d9df82b70b124f0762a
3
+ metadata.gz: deb35356d8b8edc1d42d302e6716a4842e22945b
4
+ data.tar.gz: 9c9c852103fec856d5033181e8b866ab95194a5a
5
5
  SHA512:
6
- metadata.gz: 1a1d425a35a804cec4bea1e1c2cc185ba435e6ffb9bf3e6c4ff1c2ca7b09ec96c23a119fa9f4b54b758ae800abd2327e1abdd7d102056365f39af4b2e31e772c
7
- data.tar.gz: 4c4d077cac14df7ba87e33c4b193e31b94690192b8a118bc3e99b09cad13f1aa521f4ea68959b9c4efa7af9acd765babe5844a1e597cd53e331753466e5bac1f
6
+ metadata.gz: 51d786a3d4d6a4601f69d6d2089b8096745f1142f7b6d16784a5789ac0b03a5e251394fb18e1825ea4f2da5f7834c505e846c0ff040ce5e4546ea9eca18b1cb1
7
+ data.tar.gz: a3dda68262d0597f1d8fbc7c14b6224c679e6820ca261a54b0c996a5faaa700c9312d698e7c854cf80827efadc834453b90ac650f97661d0acf66861a75f8b68
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ + **1.4.1** - _05/09/2018_
4
+ - Add the capability to specify an alternate base application / engine the routes are derived from.
5
+ This capability is specific to documemtation generation.
6
+
3
7
  + **1.3.0** - _04/12/2018_
4
8
  - Add the capability to nest fields under evaluable parent blocks where the nested fields are evaluated
5
9
  with the resulting value of the parent field.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brainstem (1.4.0)
4
+ brainstem (1.4.1)
5
5
  activerecord (>= 4.1)
6
6
  activesupport (>= 4.1)
7
7
 
@@ -22,12 +22,12 @@ GEM
22
22
  arel (8.0.0)
23
23
  coderay (1.1.2)
24
24
  concurrent-ruby (1.0.5)
25
- database_cleaner (1.6.2)
25
+ database_cleaner (1.6.1)
26
26
  db-query-matchers (0.9.0)
27
27
  activesupport (>= 4.0, <= 6.0)
28
28
  rspec (~> 3.0)
29
29
  diff-lcs (1.3)
30
- i18n (0.9.1)
30
+ i18n (0.9.0)
31
31
  concurrent-ruby (~> 1.0)
32
32
  method_source (0.9.0)
33
33
  minitest (5.10.3)
@@ -108,16 +108,11 @@ module Brainstem
108
108
  end
109
109
 
110
110
  #
111
- # Defines the application or engine that all routes will be fetched from.
111
+ # Defines the alternate application or engine that all routes will be fetched from.
112
112
  #
113
- # Is a proc because most relevant classes are not loaded until much
114
- # later.
115
- #
116
- # @see Brainstem::ApiDocs::RailsIntrospector#base_application_proc=
113
+ # @see Brainstem::ApiDocs::RailsIntrospector#base_application_class=
117
114
  #
118
- config_accessor(:base_application_proc) do
119
- Proc.new { Rails.application }
120
- end
115
+ config_accessor(:base_application_class) { nil }
121
116
 
122
117
 
123
118
  #
@@ -15,7 +15,7 @@ module Brainstem
15
15
  #
16
16
  def load_environment!
17
17
  load rails_environment_file unless env_already_loaded?
18
- ::Rails.application.eager_load!
18
+ base_application.eager_load!
19
19
 
20
20
  validate!
21
21
  rescue LoadError => e
@@ -47,6 +47,16 @@ module Brainstem
47
47
  end
48
48
 
49
49
 
50
+ #
51
+ # Returns the alternate application class or defaults to Rails.application
52
+ #
53
+ # @return [Class] The base application class
54
+ #
55
+ def base_application
56
+ base_application_class.present? ? base_application_class.constantize : ::Rails.application
57
+ end
58
+
59
+
50
60
  #
51
61
  # Returns an array of hashes describing the endpoints of the
52
62
  # application. See +routes_method+ for the keys of those hashes.
@@ -70,7 +80,7 @@ module Brainstem
70
80
  :rails_environment_file,
71
81
  :base_presenter_class,
72
82
  :base_controller_class,
73
- :base_application_proc
83
+ :base_application_class
74
84
  ]
75
85
  end
76
86
 
@@ -177,21 +187,26 @@ module Brainstem
177
187
 
178
188
 
179
189
  #
180
- # Returns a proc that will return the application or engine to get routes from.
190
+ # Returns the name of the alternate application or engine to get routes from.
181
191
  #
182
- # @return [Proc] Proc that returns the Rails application or an engine
192
+ # Because the initializer that contains configuration data is unlikely
193
+ # to have been loaded, this may also return a Proc, which will be called
194
+ # after the environment is loaded.
183
195
  #
184
- def base_application_proc
185
- @base_application_proc ||= Proc.new { Rails.application }
196
+ # @return [String,Nil] returns the name of the alternate application or engine.
197
+ #
198
+ def base_application_class
199
+ proc_or_string = @base_application_class
200
+ proc_or_string.respond_to?(:call) ? proc_or_string.call : proc_or_string
186
201
  end
187
202
 
188
203
 
189
204
  #
190
- # Allows for the specification for an alternate base application
205
+ # Allows for the specification for an alternate base application name
191
206
  #
192
- # @param [Proc] Proc that returns the Rails application or an engine
207
+ # @param [Nil,String] returns the name of the alternate application or engine
193
208
  #
194
- attr_writer :base_application_proc
209
+ attr_writer :base_application_class
195
210
 
196
211
 
197
212
  #
@@ -207,7 +222,7 @@ module Brainstem
207
222
  #
208
223
  def routes_method
209
224
  @routes_method ||= Proc.new do
210
- base_application_proc.call.routes.routes.map do |route|
225
+ base_application.routes.routes.map do |route|
211
226
  next unless route.defaults.has_key?(:controller) &&
212
227
  controller_const = "#{route.defaults[:controller]}_controller"
213
228
  .classify
@@ -49,6 +49,7 @@ module Brainstem
49
49
  args_for_introspector: {
50
50
  base_presenter_class: ::Brainstem::ApiDocs.method(:base_presenter_class),
51
51
  base_controller_class: ::Brainstem::ApiDocs.method(:base_controller_class),
52
+ base_application_class: ::Brainstem::ApiDocs.method(:base_application_class),
52
53
  },
53
54
  },
54
55
  }
@@ -148,6 +149,11 @@ module Brainstem
148
149
  end
149
150
 
150
151
 
152
+ opts.on('--base-application-class=CLASS', "which class to look up routes on") do |o|
153
+ options[:builder][:args_for_introspector][:base_application_class] = o
154
+ end
155
+
156
+
151
157
  opts.on('--controller-matches=MATCH',
152
158
  'a case-sensitive regexp used to winnow the list of '\
153
159
  'controllers. It is matched against the constant, not '\
@@ -1,3 +1,3 @@
1
1
  module Brainstem
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -114,6 +114,43 @@ module Brainstem
114
114
  end
115
115
  end
116
116
 
117
+ describe "#base_application" do
118
+ before do
119
+ stub.any_instance_of(described_class).validate!
120
+ end
121
+
122
+ context "when custom base_application_class is not given" do
123
+ subject do
124
+ described_class.with_loaded_environment(default_args)
125
+ end
126
+
127
+ it "returns nil" do
128
+ expect(subject.send(:base_application_class)).to be_nil
129
+ end
130
+
131
+ it "returns the descendants of the base controller class" do
132
+ expect(subject.base_application).to eq(::Rails.application)
133
+ end
134
+ end
135
+
136
+ context "when custom base_application_class is given" do
137
+ subject do
138
+ described_class.with_loaded_environment(
139
+ default_args.merge(base_application_class: "::FakeApiEngine")
140
+ )
141
+ end
142
+
143
+ it "allows the specification of a custom base_application_class" do
144
+ expect(subject.send(:base_application_class).to_s)
145
+ .to eq "::FakeApiEngine"
146
+ end
147
+
148
+ it "returns the descendants of the base controller class" do
149
+ expect(subject.base_application).to eq(FakeApiEngine)
150
+ end
151
+ end
152
+ end
153
+
117
154
  describe "#routes" do
118
155
  let(:a_proc) { Object.new }
119
156
 
@@ -161,27 +198,10 @@ module Brainstem
161
198
  end
162
199
 
163
200
  context "with an alternate base application or engine provided" do
164
- let(:base_application_proc) { Proc.new { FakeRailsApplication.new(true, routes) } }
165
- let(:routes) { FakeRailsRoutesObject.new([route_1, route_2]) }
166
- let(:route_1) {
167
- FakeRailsRoute.new(
168
- "fake_descendant",
169
- FakeRailsRoutePathObject.new(spec: '/fake_route_1'),
170
- { controller: "fake_descendant", action: "show" },
171
- { :request_method => /^GET$/ }
172
- )
173
- }
174
- let(:route_2) {
175
- FakeRailsRoute.new(
176
- "fake_descendant",
177
- FakeRailsRoutePathObject.new(spec: '/fake_route_2'),
178
- { controller: "fake_descendant", action: "show" },
179
- { :request_method => /^GET$/ }
180
- )
181
- }
201
+ let(:base_application_class) { "FakeApiEngine" }
182
202
 
183
203
  subject do
184
- described_class.with_loaded_environment(default_args.merge({ base_application_proc: base_application_proc }))
204
+ described_class.with_loaded_environment(default_args.merge({ base_application_class: base_application_class }))
185
205
  end
186
206
 
187
207
  it "recognizes the configured application or engine's routes" do
@@ -21,7 +21,7 @@ module Brainstem
21
21
  output_extension
22
22
  base_presenter_class
23
23
  base_controller_class
24
- base_application_proc
24
+ base_application_class
25
25
  document_empty_presenter_associations
26
26
  document_empty_presenter_filters
27
27
  ).each do |meth|
@@ -33,6 +33,15 @@ module Brainstem
33
33
  end
34
34
  end
35
35
 
36
+ context "when --base-application-class" do
37
+ let(:args) { %w(--base-application-class=::Api::Engine) }
38
+
39
+ it "sets sink to a ControllerPresenterMultifileSink" do
40
+ expect(subject.options).to have_key :builder
41
+ expect(subject.options[:builder][:args_for_introspector][:base_application_class]).to eq("::Api::Engine")
42
+ end
43
+ end
44
+
36
45
  context "when --output-dir" do
37
46
  let(:args) { %w(--output-dir=./blah) }
38
47
 
data/spec/dummy/rails.rb CHANGED
@@ -39,7 +39,6 @@ class Rails
39
39
  end
40
40
  end
41
41
 
42
-
43
42
  class FakeBasePresenter; end
44
43
  class FakeDescendantPresenter < FakeBasePresenter; end
45
44
 
@@ -47,3 +46,26 @@ class FakeBaseController; end
47
46
  class FakeDescendantController < FakeBaseController; end
48
47
 
49
48
  class FakeNonDescendantController; end
49
+
50
+ class FakeApiEngine
51
+ def self.eager_load!;end
52
+ def self.routes
53
+ @routes ||= begin
54
+ route_1 = FakeRailsRoute.new(
55
+ "fake_descendant",
56
+ FakeRailsRoutePathObject.new(spec: '/fake_route_1'),
57
+ { controller: "fake_descendant", action: "show" },
58
+ { :request_method => /^GET$/ }
59
+ )
60
+
61
+ route_2 = FakeRailsRoute.new(
62
+ "fake_descendant",
63
+ FakeRailsRoutePathObject.new(spec: '/fake_route_2'),
64
+ { controller: "fake_descendant", action: "show" },
65
+ { :request_method => /^GET$/ }
66
+ )
67
+
68
+ FakeRailsRoutesObject.new([ route_1, route_2 ])
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainstem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mavenlink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-04 00:00:00.000000000 Z
11
+ date: 2018-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord