Skip to content
This repository
Browse code

Refactor of ::Rails module

1. Used ActiveSupport::Autoload to dry-up the autoload definitions.
2. Used ActiveSupport's delegate to dry up the application proxied
   attributes.
3. Did a little white space change on Rails.groups.
  • Loading branch information...
commit 50be56dcdeb94679106ba02168a0fc1f87265d5a 1 parent 0d22947
Genadi Samokovarov authored June 11, 2013

Showing 1 changed file with 10 additions and 12 deletions. Show diff stats Hide diff stats

  1. 22  railties/lib/rails.rb
22  railties/lib/rails.rb
@@ -3,7 +3,9 @@
3 3
 require 'pathname'
4 4
 
5 5
 require 'active_support'
  6
+require 'active_support/dependencies/autoload'
6 7
 require 'active_support/core_ext/kernel/reporting'
  8
+require 'active_support/core_ext/module/delegation'
7 9
 require 'active_support/core_ext/array/extract_options'
8 10
 
9 11
 require 'rails/application'
@@ -20,26 +22,22 @@
20 22
 end
21 23
 
22 24
 module Rails
23  
-  autoload :Info, 'rails/info'
24  
-  autoload :InfoController,    'rails/info_controller'
25  
-  autoload :WelcomeController, 'rails/welcome_controller'
  25
+  extend ActiveSupport::Autoload
  26
+
  27
+  autoload :Info
  28
+  autoload :InfoController
  29
+  autoload :WelcomeController
26 30
 
27 31
   class << self
28 32
     attr_accessor :application, :cache, :logger
29 33
 
  34
+    delegate :initialize!, :initialized?, to: :application
  35
+
30 36
     # The Configuration instance used to configure the Rails environment
31 37
     def configuration
32 38
       application.config
33 39
     end
34 40
 
35  
-    def initialize!
36  
-      application.initialize!
37  
-    end
38  
-
39  
-    def initialized?
40  
-      application.initialized?
41  
-    end
42  
-
43 41
     def backtrace_cleaner
44 42
       @backtrace_cleaner ||= begin
45 43
         # Relies on Active Support, so we have to lazy load to postpone definition until AS has been loaded
@@ -76,7 +74,7 @@ def groups(*groups)
76 74
       env = Rails.env
77 75
       groups.unshift(:default, env)
78 76
       groups.concat ENV["RAILS_GROUPS"].to_s.split(",")
79  
-      groups.concat hash.map { |k,v| k if v.map(&:to_s).include?(env) }
  77
+      groups.concat hash.map { |k, v| k if v.map(&:to_s).include?(env) }
80 78
       groups.compact!
81 79
       groups.uniq!
82 80
       groups

0 notes on commit 50be56d

Please sign in to comment.
Something went wrong with that request. Please try again.