aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md17
-rw-r--r--railties/lib/rails/application/configuration.rb14
-rw-r--r--railties/test/application/configuration/base_test.rb37
-rw-r--r--railties/test/application/configuration/custom_test.rb15
4 files changed, 82 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 651f40007e..dac554e015 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,20 @@
+* Pull in the custom configuration concept from dhh/custom_configuration, which allows you to
+ configure your own code through the Rails configuration object with custom configuration:
+
+ # config/environments/production.rb
+ config.x.payment_processing.schedule = :daily
+ config.x.payment_processing.retries = 3
+ config.x.super_debugger = true
+
+ These configuration points are then available through the configuration object:
+
+ Rails.configuration.x.payment_processing.schedule # => :daily
+ Rails.configuration.x.payment_processing.retries # => 3
+ Rails.configuration.x.super_debugger # => true
+ Rails.configuration.x.super_debugger.not_set # => nil
+
+ *DHH*
+
* Scaffold generator `_form` partial adds `class="field"` for password
confirmation fields.
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 5e8f4de847..782bc4b0f1 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -13,7 +13,7 @@ module Rails
:railties_order, :relative_url_root, :secret_key_base, :secret_token,
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
:time_zone, :reload_classes_only_on_change,
- :beginning_of_week, :filter_redirect
+ :beginning_of_week, :filter_redirect, :x
attr_writer :log_level
attr_reader :encoding
@@ -48,6 +48,7 @@ module Rails
@eager_load = nil
@secret_token = nil
@secret_key_base = nil
+ @x = Custom.new
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = true
@@ -154,6 +155,17 @@ module Rails
def annotations
SourceAnnotationExtractor::Annotation
end
+
+ private
+ class Custom
+ def initialize
+ @configurations = Hash.new
+ end
+
+ def method_missing(method, *args)
+ @configurations[method] ||= ActiveSupport::OrderedOptions.new
+ end
+ end
end
end
end
diff --git a/railties/test/application/configuration/base_test.rb b/railties/test/application/configuration/base_test.rb
new file mode 100644
index 0000000000..d6a82b139d
--- /dev/null
+++ b/railties/test/application/configuration/base_test.rb
@@ -0,0 +1,37 @@
+require 'isolation/abstract_unit'
+require 'rack/test'
+require 'env_helpers'
+
+module ApplicationTests
+ module ConfigurationTests
+ class BaseTest < ActiveSupport::TestCase
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ end
+
+ def teardown
+ teardown_app
+ FileUtils.rm_rf(new_app) if File.directory?(new_app)
+ end
+
+ private
+ def new_app
+ File.expand_path("#{app_path}/../new_app")
+ end
+
+ def copy_app
+ FileUtils.cp_r(app_path, new_app)
+ end
+
+ def app
+ @app ||= Rails.application
+ end
+
+ def require_environment
+ require "#{app_path}/config/environment"
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/test/application/configuration/custom_test.rb b/railties/test/application/configuration/custom_test.rb
new file mode 100644
index 0000000000..045537fc28
--- /dev/null
+++ b/railties/test/application/configuration/custom_test.rb
@@ -0,0 +1,15 @@
+require 'application/configuration/base_test'
+
+class ApplicationTests::ConfigurationTests::CustomTest < ApplicationTests::ConfigurationTests::BaseTest
+ test 'access custom configuration point' do
+ add_to_config <<-RUBY
+ config.x.resque.inline_jobs = :always
+ config.x.resque.timeout = 60
+ RUBY
+ require_environment
+
+ assert_equal :always, Rails.configuration.x.resque.inline_jobs
+ assert_equal 60, Rails.configuration.x.resque.timeout
+ assert_nil Rails.configuration.x.resque.nothing
+ end
+end