Class: Peck::Rails
- Inherits:
-
Object
show all
- Defined in:
- lib/peck_on_rails.rb
Defined Under Namespace
Modules: BacktraceCleaning
Classes: Context, Controller, Helper, Model
Constant Summary
collapse
- HELPER_RE =
/Helper$/
Class Method Summary
collapse
Class Method Details
.context_type(context, subject) ⇒ Object
226
227
228
229
230
231
232
|
# File 'lib/peck_on_rails.rb', line 226
def self.context_type(context, subject)
context_type =
context_type_for_description(context, subject) ||
context_type_for_subject(context, subject)
Peck.log("Using `#{context_type}' as context type for `#{subject.name}'")
context_type
end
|
.context_type_for_description(context, subject) ⇒ Object
206
207
208
209
210
|
# File 'lib/peck_on_rails.rb', line 206
def self.context_type_for_description(context, subject)
context.description.find do |subject|
subject.is_a?(Symbol)
end
end
|
.context_type_for_subject(context, subject) ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/peck_on_rails.rb', line 214
def self.context_type_for_subject(context, subject)
if subject < ActionController::Base
:controller
elsif subject < ActiveRecord::Base
:model
elsif subject.name =~ HELPER_RE
:helper
else
:plain
end
end
|
.init ⇒ Object
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'lib/peck_on_rails.rb', line 234
def self.init
Peck.log("Setting up Peck::Rails")
proc do |context|
subject = Peck::Rails.subject(context)
context_type = Peck::Rails.context_type(context, subject)
[
Peck::Rails::Context,
Peck::Rails::Helper,
Peck::Rails::Model,
Peck::Rails::Controller
].each do |klass|
klass.send(:init, context, context_type, subject)
end
end
end
|
.subject(context) ⇒ Object
202
203
204
|
# File 'lib/peck_on_rails.rb', line 202
def self.subject(context)
context.description.find { |a| a.is_a?(Module) }
end
|