incline 0.2.17 → 0.2.18

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: 26b57eeb71154ecd78ca518cff42f4611b83039d
4
- data.tar.gz: deaf5ce2ff1810f725b928d00aec489e80e63a76
3
+ metadata.gz: 5d480afc97f1235565c6a453fc357d1a3055b3b0
4
+ data.tar.gz: 439acc31750a1a618f1255f3fcf6d4efaea31492
5
5
  SHA512:
6
- metadata.gz: 0b1350992064923d07dbdd0de0257ebbe98f9bf308a62b5b35d3dbe36dfd9c90f905fb1b18d16009ba82b4ee7438eb090820c4c80424a3698bd240cb58a96917
7
- data.tar.gz: 25bc635ab9533868136a17239a0141ab7922d74f814eb11a99de455055334b04cbcbf052cfab22b7906c9b88be7c08bcbf06f68498fec9cfae78acf6b40d7d0c
6
+ metadata.gz: 3dd29096c66f7cf8678dee49f828fc9f0dfa79aa014837068fc1194ba031dc48ab915bf211344934e20cc495954a9267c9cea8837c609733d7b4d2b6ca16eddf
7
+ data.tar.gz: 2e9f293bdd559bf718ea385031de52c15683f3978613df97370712dd518c76e8bc1899347edd3cfc0cc33ae5d1b99d3f1968124d16a1b99ca38d3a2e5c183e96
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- incline (0.2.17)
4
+ incline (0.2.18)
5
5
  ansi (~> 1.5.0)
6
6
  bcrypt
7
7
  bootstrap-sass
@@ -31,41 +31,7 @@ module Incline
31
31
  self.allow_anon = self.require_anon = self.require_admin = self.unknown_controller = self.non_standard = false
32
32
 
33
33
  self.unknown_controller = true
34
- klass =
35
- begin
36
- (controller_name + '_controller').classify.constantize
37
- rescue NameError
38
- nil
39
- end
40
-
41
- unless klass
42
- options =
43
- if controller_name.include?('/')
44
- ns = controller_name.rpartition('/')[0]
45
- ctrl = controller_name.rpartition('/')[2]
46
- options = [
47
- "#{ns}/app/controllers/#{ns}/#{ctrl}_controller",
48
- "app/controllers/#{ns}/#{ctrl}_controller",
49
- "#{ns}/app/controllers/#{ctrl}_controller",
50
- "#{ns}/#{ctrl}_controller"
51
- ]
52
- else
53
- options = [
54
- "app/controllers/#{controller_name}_controller",
55
- "#{controller_name}_controller"
56
- ]
57
- end
58
-
59
- while (file = options.shift)
60
- begin
61
- require file
62
- klass = (controller_name + '_controller').classify.constantize
63
- break
64
- rescue LoadError, NameError
65
- # just preventing the error from bubbling up.
66
- end
67
- end
68
- end
34
+ klass = ::Incline.get_controller_class(controller_name)
69
35
 
70
36
  if klass
71
37
  self.unknown_controller = false
@@ -1,3 +1,3 @@
1
1
  module Incline
2
- VERSION = "0.2.17"
2
+ VERSION = "0.2.18"
3
3
  end
data/lib/incline.rb CHANGED
@@ -146,6 +146,66 @@ module Incline
146
146
  def self.migrate!
147
147
  ActiveRecord::Migrator.migrate File.expand_path('../../db/migrate', __FILE__), nil
148
148
  end
149
+
150
+ ##
151
+ # Locates and loads a controller's class definition.
152
+ #
153
+ # If found, returns the controller class, otherwise nil.
154
+ def self.get_controller_class(controller_name)
155
+ controller_name += '_controller' unless controller_name =~ /_controller$/
156
+ class_name = controller_name.classify
157
+
158
+ klass =
159
+ begin
160
+ class_name.constantize
161
+ rescue NameError
162
+ nil
163
+ end
164
+
165
+ if klass
166
+ unless klass <= ::ActionController::Base
167
+ ::Incline::Log::warn "The '#{class_name}' class does not inherit from 'ActionController::Base'."
168
+ return nil
169
+ end
170
+ end
171
+
172
+ unless klass
173
+ file_options =
174
+ if controller_name.include?('/')
175
+ ns,_,ctrl = controller_name.rpartition('/')
176
+ [
177
+ "#{ns}/app/controllers/#{ns}/#{ctrl}_controller",
178
+ "app/controllers/#{ns}/#{ctrl}_controller",
179
+ "#{ns}/app/controllers/#{ctrl}_controller",
180
+ "#{ns}/#{ctrl}_controller"
181
+ ]
182
+ else
183
+ [
184
+ "app/controllers/#{controller_name}_controller",
185
+ "#{controller_name}_controller"
186
+ ]
187
+ end
188
+
189
+ while (file = file_options.shift)
190
+ begin
191
+ require file
192
+ klass = class_name.constantize
193
+ if klass <= ::ActionController::Base
194
+ ::Incline::Log::debug "Found '#{class_name}' in '#{file}'."
195
+ else
196
+ ::Incline::Log::warn "Found '#{class_name}' in '#{file}', but it does not inherit from 'ActionController::Base'."
197
+ klass = nil
198
+ end
199
+ break
200
+ rescue LoadError, NameError
201
+ # don't bubble up these errors.
202
+ klass = nil
203
+ end
204
+ end
205
+ end
206
+
207
+ klass
208
+ end
149
209
 
150
210
  private
151
211
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beau Barker