Skip to content
This repository
Browse code

Separate Rails module methods, the config object, and the initializer…

… into separate files.
  • Loading branch information...
commit 3aad4d7fbec6b0881733d3a9b2aff756f775ad35 1 parent ce9d9fd
authored June 23, 2009
336  railties/lib/initializer.rb
@@ -5,344 +5,12 @@
5 5
 require 'rails/version'
6 6
 require 'rails/gem_dependency'
7 7
 require 'rails/rack'
  8
+require 'rails/core'
  9
+require 'rails/configuration'
8 10
 
9 11
 RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
10 12
 
11 13
 module Rails
12  
-  # Needs to be duplicated from Active Support since its needed before Active
13  
-  # Support is available. Here both Options and Hash are namespaced to prevent
14  
-  # conflicts with other implementations AND with the classes residing in Active Support.
15  
-  # ---
16  
-  # TODO: w0t?
17  
-  class << self
18  
-    # The Configuration instance used to configure the Rails environment
19  
-    def configuration
20  
-      @@configuration
21  
-    end
22  
-
23  
-    def configuration=(configuration)
24  
-      @@configuration = configuration
25  
-    end
26  
-
27  
-    def initialized?
28  
-      @initialized || false
29  
-    end
30  
-
31  
-    def initialized=(initialized)
32  
-      @initialized ||= initialized
33  
-    end
34  
-
35  
-    def logger
36  
-      if defined?(RAILS_DEFAULT_LOGGER)
37  
-        RAILS_DEFAULT_LOGGER
38  
-      else
39  
-        nil
40  
-      end
41  
-    end
42  
-
43  
-    def backtrace_cleaner
44  
-      @@backtrace_cleaner ||= begin
45  
-        # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded
46  
-        require 'rails/backtrace_cleaner'
47  
-        Rails::BacktraceCleaner.new
48  
-      end
49  
-    end
50  
-
51  
-    def root
52  
-      Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT)
53  
-    end
54  
-
55  
-    def env
56  
-      @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
57  
-    end
58  
-
59  
-    def cache
60  
-      RAILS_CACHE
61  
-    end
62  
-
63  
-    def version
64  
-      VERSION::STRING
65  
-    end
66  
-
67  
-    def public_path
68  
-      @@public_path ||= self.root ? File.join(self.root, "public") : "public"
69  
-    end
70  
-
71  
-    def public_path=(path)
72  
-      @@public_path = path
73  
-    end
74  
-  end
75  
-
76  
-  class OrderedOptions < Array #:nodoc:
77  
-    def []=(key, value)
78  
-      key = key.to_sym
79  
-
80  
-      if pair = find_pair(key)
81  
-        pair.pop
82  
-        pair << value
83  
-      else
84  
-        self << [key, value]
85  
-      end
86  
-    end
87  
-
88  
-    def [](key)
89  
-      pair = find_pair(key.to_sym)
90  
-      pair ? pair.last : nil
91  
-    end
92  
-
93  
-    def method_missing(name, *args)
94  
-      if name.to_s =~ /(.*)=$/
95  
-        self[$1.to_sym] = args.first
96  
-      else
97  
-        self[name]
98  
-      end
99  
-    end
100  
-
101  
-  private
102  
-    def find_pair(key)
103  
-      self.each { |i| return i if i.first == key }
104  
-      return false
105  
-    end
106  
-  end
107  
-
108  
-  class Configuration
109  
-    attr_accessor :cache_classes, :load_paths, :eager_load_paths, :framework_paths,
110  
-                  :load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks,
111  
-                  :frameworks, :framework_root_path, :root_path, :plugin_paths, :plugins,
112  
-                  :plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins,
113  
-                  :i18n, :gems, :whiny_nils, :consider_all_requests_local,
114  
-                  :action_controller, :active_record, :action_view, :active_support,
115  
-                  :action_mailer, :active_resource,
116  
-                  :log_path, :log_level, :logger, :preload_frameworks,
117  
-                  :database_configuration_file, :cache_store, :time_zone,
118  
-                  :view_path, :metals, :controller_paths, :routes_configuration_file,
119  
-                  :eager_load_paths, :dependency_loading
120  
-
121  
-    def initialize
122  
-      set_root_path!
123  
-
124  
-      @framework_paths              = []
125  
-      @load_once_paths              = []
126  
-      @after_initialize_blocks      = []
127  
-      @loaded_plugins               = []
128  
-      @dependency_loading           = true
129  
-      @eager_load_paths             = default_eager_load_paths
130  
-      @load_paths                   = default_load_paths
131  
-      @plugin_paths                 = default_plugin_paths
132  
-      @frameworks                   = default_frameworks
133  
-      @plugin_loader                = default_plugin_loader
134  
-      @plugin_locators              = default_plugin_locators
135  
-      @gems                         = default_gems
136  
-      @i18n                         = default_i18n
137  
-      @log_path                     = default_log_path
138  
-      @log_level                    = default_log_level
139  
-      @cache_store                  = default_cache_store
140  
-      @view_path                    = default_view_path
141  
-      @controller_paths             = default_controller_paths
142  
-      @routes_configuration_file    = default_routes_configuration_file
143  
-      @database_configuration_file  = default_database_configuration_file
144  
-
145  
-      for framework in default_frameworks
146  
-        self.send("#{framework}=", Rails::OrderedOptions.new)
147  
-      end
148  
-      self.active_support = Rails::OrderedOptions.new
149  
-    end
150  
-
151  
-    def after_initialize(&blk)
152  
-      @after_initialize_blocks << blk if blk
153  
-    end
154  
-
155  
-    def set_root_path!
156  
-      raise 'RAILS_ROOT is not set' unless defined?(RAILS_ROOT)
157  
-      raise 'RAILS_ROOT is not a directory' unless File.directory?(RAILS_ROOT)
158  
-
159  
-      self.root_path =
160  
-        # Pathname is incompatible with Windows, but Windows doesn't have
161  
-        # real symlinks so File.expand_path is safe.
162  
-        if RUBY_PLATFORM =~ /(:?mswin|mingw)/
163  
-          File.expand_path(RAILS_ROOT)
164  
-
165  
-        # Otherwise use Pathname#realpath which respects symlinks.
166  
-        else
167  
-          Pathname.new(RAILS_ROOT).realpath.to_s
168  
-        end
169  
-
170  
-      RAILS_ROOT.replace self.root_path
171  
-    end
172  
-
173  
-    # Enable threaded mode. Allows concurrent requests to controller actions and
174  
-    # multiple database connections. Also disables automatic dependency loading
175  
-    # after boot, and disables reloading code on every request, as these are
176  
-    # fundamentally incompatible with thread safety.
177  
-    def threadsafe!
178  
-      self.preload_frameworks = true
179  
-      self.cache_classes = true
180  
-      self.dependency_loading = false
181  
-      self.action_controller.allow_concurrency = true
182  
-      self
183  
-    end
184  
-
185  
-    def framework_paths
186  
-      paths = %w(railties railties/lib activesupport/lib)
187  
-      paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view)
188  
-
189  
-      [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
190  
-        paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework)
191  
-      end
192  
-
193  
-      paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
194  
-    end
195  
-
196  
-    def framework_root_path
197  
-      defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
198  
-    end
199  
-
200  
-    # TODO: Fix this when there is an application object
201  
-    def middleware
202  
-      require 'action_controller'
203  
-      ActionController::Dispatcher.middleware
204  
-    end
205  
-
206  
-    # Loads and returns the contents of the #database_configuration_file. The
207  
-    # contents of the file are processed via ERB before being sent through
208  
-    # YAML::load.
209  
-    def database_configuration
210  
-      require 'erb'
211  
-      YAML::load(ERB.new(IO.read(database_configuration_file)).result)
212  
-    end
213  
-
214  
-    def default_routes_configuration_file
215  
-      File.join(root_path, 'config', 'routes.rb')
216  
-    end
217  
-
218  
-    def default_controller_paths
219  
-      paths = [File.join(root_path, 'app', 'controllers')]
220  
-      paths.concat builtin_directories
221  
-      paths
222  
-    end
223  
-
224  
-    def default_cache_store
225  
-      if File.exist?("#{root_path}/tmp/cache/")
226  
-        [ :file_store, "#{root_path}/tmp/cache/" ]
227  
-      else
228  
-        :memory_store
229  
-      end
230  
-    end
231  
-
232  
-    def default_database_configuration_file
233  
-      File.join(root_path, 'config', 'database.yml')
234  
-    end
235  
-
236  
-    def default_view_path
237  
-      File.join(root_path, 'app', 'views')
238  
-    end
239  
-
240  
-    def default_eager_load_paths
241  
-      %w(
242  
-        app/metal
243  
-        app/models
244  
-        app/controllers
245  
-        app/helpers
246  
-      ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
247  
-    end
248  
-
249  
-    def default_load_paths
250  
-      paths = []
251  
-
252  
-      # Add the old mock paths only if the directories exists
253  
-      paths.concat(Dir["#{root_path}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root_path}/test/mocks/#{RAILS_ENV}")
254  
-
255  
-      # Add the app's controller directory
256  
-      paths.concat(Dir["#{root_path}/app/controllers/"])
257  
-
258  
-      # Followed by the standard includes.
259  
-      paths.concat %w(
260  
-        app
261  
-        app/metal
262  
-        app/models
263  
-        app/controllers
264  
-        app/helpers
265  
-        app/services
266  
-        lib
267  
-        vendor
268  
-      ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
269  
-
270  
-      paths.concat builtin_directories
271  
-    end
272  
-
273  
-    def builtin_directories
274  
-      # Include builtins only in the development environment.
275  
-      (RAILS_ENV == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
276  
-    end
277  
-
278  
-    def default_log_path
279  
-      File.join(root_path, 'log', "#{RAILS_ENV}.log")
280  
-    end
281  
-
282  
-    def default_log_level
283  
-      RAILS_ENV == 'production' ? :info : :debug
284  
-    end
285  
-
286  
-    def default_frameworks
287  
-      [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
288  
-    end
289  
-
290  
-    def default_plugin_paths
291  
-      ["#{root_path}/vendor/plugins"]
292  
-    end
293  
-
294  
-    def default_plugin_loader
295  
-      require 'rails/plugin/loader'
296  
-      Plugin::Loader
297  
-    end
298  
-
299  
-    def default_plugin_locators
300  
-      require 'rails/plugin/locator'
301  
-      locators = []
302  
-      locators << Plugin::GemLocator if defined? Gem
303  
-      locators << Plugin::FileSystemLocator
304  
-    end
305  
-
306  
-    def default_i18n
307  
-      i18n = Rails::OrderedOptions.new
308  
-      i18n.load_path = []
309  
-
310  
-      if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
311  
-        i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
312  
-        i18n.load_path.flatten!
313  
-      end
314  
-
315  
-      i18n
316  
-    end
317  
-
318  
-    # Adds a single Gem dependency to the rails application. By default, it will require
319  
-    # the library with the same name as the gem. Use :lib to specify a different name.
320  
-    #
321  
-    #   # gem 'aws-s3', '>= 0.4.0'
322  
-    #   # require 'aws/s3'
323  
-    #   config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
324  
-    #     :source => "http://code.whytheluckystiff.net"
325  
-    #
326  
-    # To require a library be installed, but not attempt to load it, pass :lib => false
327  
-    #
328  
-    #   config.gem 'qrp', :version => '0.4.1', :lib => false
329  
-    def gem(name, options = {})
330  
-      @gems << Rails::GemDependency.new(name, options)
331  
-    end
332  
-
333  
-    def default_gems
334  
-      []
335  
-    end
336  
-
337  
-    def environment_path
338  
-      "#{root_path}/config/environments/#{RAILS_ENV}.rb"
339  
-    end
340  
-
341  
-    def reload_plugins?
342  
-      @reload_plugins
343  
-    end
344  
-  end
345  
-
346 14
   class Initializer
347 15
     class Error < StandardError ; end
348 16
 
239  railties/lib/rails/configuration.rb
... ...
@@ -0,0 +1,239 @@
  1
+module Rails
  2
+  class Configuration
  3
+    attr_accessor :cache_classes, :load_paths, :eager_load_paths, :framework_paths,
  4
+                  :load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks,
  5
+                  :frameworks, :framework_root_path, :root_path, :plugin_paths, :plugins,
  6
+                  :plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins,
  7
+                  :i18n, :gems, :whiny_nils, :consider_all_requests_local,
  8
+                  :action_controller, :active_record, :action_view, :active_support,
  9
+                  :action_mailer, :active_resource,
  10
+                  :log_path, :log_level, :logger, :preload_frameworks,
  11
+                  :database_configuration_file, :cache_store, :time_zone,
  12
+                  :view_path, :metals, :controller_paths, :routes_configuration_file,
  13
+                  :eager_load_paths, :dependency_loading
  14
+
  15
+    def initialize
  16
+      set_root_path!
  17
+
  18
+      @framework_paths              = []
  19
+      @load_once_paths              = []
  20
+      @after_initialize_blocks      = []
  21
+      @loaded_plugins               = []
  22
+      @dependency_loading           = true
  23
+      @eager_load_paths             = default_eager_load_paths
  24
+      @load_paths                   = default_load_paths
  25
+      @plugin_paths                 = default_plugin_paths
  26
+      @frameworks                   = default_frameworks
  27
+      @plugin_loader                = default_plugin_loader
  28
+      @plugin_locators              = default_plugin_locators
  29
+      @gems                         = default_gems
  30
+      @i18n                         = default_i18n
  31
+      @log_path                     = default_log_path
  32
+      @log_level                    = default_log_level
  33
+      @cache_store                  = default_cache_store
  34
+      @view_path                    = default_view_path
  35
+      @controller_paths             = default_controller_paths
  36
+      @routes_configuration_file    = default_routes_configuration_file
  37
+      @database_configuration_file  = default_database_configuration_file
  38
+
  39
+      for framework in default_frameworks
  40
+        self.send("#{framework}=", Rails::OrderedOptions.new)
  41
+      end
  42
+      self.active_support = Rails::OrderedOptions.new
  43
+    end
  44
+
  45
+    def after_initialize(&blk)
  46
+      @after_initialize_blocks << blk if blk
  47
+    end
  48
+
  49
+    def set_root_path!
  50
+      raise 'RAILS_ROOT is not set' unless defined?(RAILS_ROOT)
  51
+      raise 'RAILS_ROOT is not a directory' unless File.directory?(RAILS_ROOT)
  52
+
  53
+      self.root_path =
  54
+        # Pathname is incompatible with Windows, but Windows doesn't have
  55
+        # real symlinks so File.expand_path is safe.
  56
+        if RUBY_PLATFORM =~ /(:?mswin|mingw)/
  57
+          File.expand_path(RAILS_ROOT)
  58
+
  59
+        # Otherwise use Pathname#realpath which respects symlinks.
  60
+        else
  61
+          Pathname.new(RAILS_ROOT).realpath.to_s
  62
+        end
  63
+
  64
+      RAILS_ROOT.replace self.root_path
  65
+    end
  66
+
  67
+    # Enable threaded mode. Allows concurrent requests to controller actions and
  68
+    # multiple database connections. Also disables automatic dependency loading
  69
+    # after boot, and disables reloading code on every request, as these are
  70
+    # fundamentally incompatible with thread safety.
  71
+    def threadsafe!
  72
+      self.preload_frameworks = true
  73
+      self.cache_classes = true
  74
+      self.dependency_loading = false
  75
+      self.action_controller.allow_concurrency = true
  76
+      self
  77
+    end
  78
+
  79
+    def framework_paths
  80
+      paths = %w(railties railties/lib activesupport/lib)
  81
+      paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view)
  82
+
  83
+      [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
  84
+        paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework)
  85
+      end
  86
+
  87
+      paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
  88
+    end
  89
+
  90
+    def framework_root_path
  91
+      defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
  92
+    end
  93
+
  94
+    # TODO: Fix this when there is an application object
  95
+    def middleware
  96
+      require 'action_controller'
  97
+      ActionController::Dispatcher.middleware
  98
+    end
  99
+
  100
+    # Loads and returns the contents of the #database_configuration_file. The
  101
+    # contents of the file are processed via ERB before being sent through
  102
+    # YAML::load.
  103
+    def database_configuration
  104
+      require 'erb'
  105
+      YAML::load(ERB.new(IO.read(database_configuration_file)).result)
  106
+    end
  107
+
  108
+    def default_routes_configuration_file
  109
+      File.join(root_path, 'config', 'routes.rb')
  110
+    end
  111
+
  112
+    def default_controller_paths
  113
+      paths = [File.join(root_path, 'app', 'controllers')]
  114
+      paths.concat builtin_directories
  115
+      paths
  116
+    end
  117
+
  118
+    def default_cache_store
  119
+      if File.exist?("#{root_path}/tmp/cache/")
  120
+        [ :file_store, "#{root_path}/tmp/cache/" ]
  121
+      else
  122
+        :memory_store
  123
+      end
  124
+    end
  125
+
  126
+    def default_database_configuration_file
  127
+      File.join(root_path, 'config', 'database.yml')
  128
+    end
  129
+
  130
+    def default_view_path
  131
+      File.join(root_path, 'app', 'views')
  132
+    end
  133
+
  134
+    def default_eager_load_paths
  135
+      %w(
  136
+        app/metal
  137
+        app/models
  138
+        app/controllers
  139
+        app/helpers
  140
+      ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
  141
+    end
  142
+
  143
+    def default_load_paths
  144
+      paths = []
  145
+
  146
+      # Add the old mock paths only if the directories exists
  147
+      paths.concat(Dir["#{root_path}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root_path}/test/mocks/#{RAILS_ENV}")
  148
+
  149
+      # Add the app's controller directory
  150
+      paths.concat(Dir["#{root_path}/app/controllers/"])
  151
+
  152
+      # Followed by the standard includes.
  153
+      paths.concat %w(
  154
+        app
  155
+        app/metal
  156
+        app/models
  157
+        app/controllers
  158
+        app/helpers
  159
+        app/services
  160
+        lib
  161
+        vendor
  162
+      ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
  163
+
  164
+      paths.concat builtin_directories
  165
+    end
  166
+
  167
+    def builtin_directories
  168
+      # Include builtins only in the development environment.
  169
+      (RAILS_ENV == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
  170
+    end
  171
+
  172
+    def default_log_path
  173
+      File.join(root_path, 'log', "#{RAILS_ENV}.log")
  174
+    end
  175
+
  176
+    def default_log_level
  177
+      RAILS_ENV == 'production' ? :info : :debug
  178
+    end
  179
+
  180
+    def default_frameworks
  181
+      [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
  182
+    end
  183
+
  184
+    def default_plugin_paths
  185
+      ["#{root_path}/vendor/plugins"]
  186
+    end
  187
+
  188
+    def default_plugin_loader
  189
+      require 'rails/plugin/loader'
  190
+      Plugin::Loader
  191
+    end
  192
+
  193
+    def default_plugin_locators
  194
+      require 'rails/plugin/locator'
  195
+      locators = []
  196
+      locators << Plugin::GemLocator if defined? Gem
  197
+      locators << Plugin::FileSystemLocator
  198
+    end
  199
+
  200
+    def default_i18n
  201
+      i18n = Rails::OrderedOptions.new
  202
+      i18n.load_path = []
  203
+
  204
+      if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
  205
+        i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
  206
+        i18n.load_path.flatten!
  207
+      end
  208
+
  209
+      i18n
  210
+    end
  211
+
  212
+    # Adds a single Gem dependency to the rails application. By default, it will require
  213
+    # the library with the same name as the gem. Use :lib to specify a different name.
  214
+    #
  215
+    #   # gem 'aws-s3', '>= 0.4.0'
  216
+    #   # require 'aws/s3'
  217
+    #   config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
  218
+    #     :source => "http://code.whytheluckystiff.net"
  219
+    #
  220
+    # To require a library be installed, but not attempt to load it, pass :lib => false
  221
+    #
  222
+    #   config.gem 'qrp', :version => '0.4.1', :lib => false
  223
+    def gem(name, options = {})
  224
+      @gems << Rails::GemDependency.new(name, options)
  225
+    end
  226
+
  227
+    def default_gems
  228
+      []
  229
+    end
  230
+
  231
+    def environment_path
  232
+      "#{root_path}/config/environments/#{RAILS_ENV}.rb"
  233
+    end
  234
+
  235
+    def reload_plugins?
  236
+      @reload_plugins
  237
+    end
  238
+  end
  239
+end
97  railties/lib/rails/core.rb
... ...
@@ -0,0 +1,97 @@
  1
+module Rails
  2
+  # Needs to be duplicated from Active Support since its needed before Active
  3
+  # Support is available. Here both Options and Hash are namespaced to prevent
  4
+  # conflicts with other implementations AND with the classes residing in Active Support.
  5
+  # ---
  6
+  # TODO: w0t?
  7
+  class << self
  8
+    # The Configuration instance used to configure the Rails environment
  9
+    def configuration
  10
+      @@configuration
  11
+    end
  12
+
  13
+    def configuration=(configuration)
  14
+      @@configuration = configuration
  15
+    end
  16
+
  17
+    def initialized?
  18
+      @initialized || false
  19
+    end
  20
+
  21
+    def initialized=(initialized)
  22
+      @initialized ||= initialized
  23
+    end
  24
+
  25
+    def logger
  26
+      if defined?(RAILS_DEFAULT_LOGGER)
  27
+        RAILS_DEFAULT_LOGGER
  28
+      else
  29
+        nil
  30
+      end
  31
+    end
  32
+
  33
+    def backtrace_cleaner
  34
+      @@backtrace_cleaner ||= begin
  35
+        # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded
  36
+        require 'rails/backtrace_cleaner'
  37
+        Rails::BacktraceCleaner.new
  38
+      end
  39
+    end
  40
+
  41
+    def root
  42
+      Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT)
  43
+    end
  44
+
  45
+    def env
  46
+      @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
  47
+    end
  48
+
  49
+    def cache
  50
+      RAILS_CACHE
  51
+    end
  52
+
  53
+    def version
  54
+      VERSION::STRING
  55
+    end
  56
+
  57
+    def public_path
  58
+      @@public_path ||= self.root ? File.join(self.root, "public") : "public"
  59
+    end
  60
+
  61
+    def public_path=(path)
  62
+      @@public_path = path
  63
+    end
  64
+  end
  65
+
  66
+  class OrderedOptions < Array #:nodoc:
  67
+    def []=(key, value)
  68
+      key = key.to_sym
  69
+
  70
+      if pair = find_pair(key)
  71
+        pair.pop
  72
+        pair << value
  73
+      else
  74
+        self << [key, value]
  75
+      end
  76
+    end
  77
+
  78
+    def [](key)
  79
+      pair = find_pair(key.to_sym)
  80
+      pair ? pair.last : nil
  81
+    end
  82
+
  83
+    def method_missing(name, *args)
  84
+      if name.to_s =~ /(.*)=$/
  85
+        self[$1.to_sym] = args.first
  86
+      else
  87
+        self[name]
  88
+      end
  89
+    end
  90
+
  91
+  private
  92
+    def find_pair(key)
  93
+      self.each { |i| return i if i.first == key }
  94
+      return false
  95
+    end
  96
+  end
  97
+end

0 notes on commit 3aad4d7

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