Permalink
Browse files

Add Rails 3 support using Railtie.

  • Loading branch information...
1 parent bf93df7 commit 2773b638f28428d3f79c3f0d04743831f85830fe @weppos weppos committed Jun 26, 2012
Showing with 34 additions and 24 deletions.
  1. +1 −0 CHANGELOG.md
  2. +1 −0 lib/simple_config.rb
  3. +29 −0 lib/simple_config/railtie.rb
  4. +0 −21 lib/tasks/simple_config.rake
  5. +3 −3 templates/configuration.rb
View
1 CHANGELOG.md
@@ -5,6 +5,7 @@
- Remove deprecated SimpleConfig::Utilities.
- Remove deprecated SimpleConfig::ControllerMixin.
- Remove pre-Rails 3 init.rb file.
+- Add Rails 3 support using Railtie.
## master
View
1 lib/simple_config.rb
@@ -1,4 +1,5 @@
require 'simple_config/version'
+require 'simple_config/railtie' if defined?(Rails)
module SimpleConfig
View
29 lib/simple_config/railtie.rb
@@ -0,0 +1,29 @@
+require 'simple_config'
+require 'rails'
+
+module Airbrake
+ class Railtie < ::Rails::Railtie
+
+ rake_tasks do
+ namespace :simpleconfig do
+ desc "Initialize SimpleConfig configurations."
+ task :setup do
+ abort("Already found config/settings. Have you already run this task?.") if File.exist?("config/settings")
+
+ mkdir("config/settings")
+ mkdir("config/initializers") unless File.exist?("config/initializers")
+
+ environments = Dir["config/environments/*.rb"].map { |f| File.basename(f, ".rb") }
+ environments << "application"
+ environments.each { |env| touch("config/settings/#{env}.rb") }
+
+ cp(
+ File.expand_path("../../../templates/configuration.rb", __FILE__),
+ "config/initializers/configuration.rb"
+ )
+ end
+ end
+ end
+
+ end
+end
View
21 lib/tasks/simple_config.rake
@@ -1,21 +0,0 @@
-require 'fileutils'
-
-namespace :simple_config do
- include FileUtils
-
- task :setup do
- raise "This task should be run from within a Rails application." unless File.exist?('config')
- raise "Already found config/settings. Have you already run this task?." if File.exist?('config/settings')
-
- mkdir('config/settings')
- mkdir("config/initializers") unless File.exist?("config/initializers")
-
- environments = Dir["config/environments/*.rb"].map { |f| File.basename(f, ".rb") }
- environments << 'application'
- environments.each { |env| touch("config/settings/#{env}.rb") }
-
- cp(File.join(File.dirname(__FILE__), *%w[.. .. templates configuration.rb]),
- "config/initializers/configuration.rb")
- end
-
-end
View
6 templates/configuration.rb
@@ -2,17 +2,17 @@
# Set here your global configuration.
# All settings can be overwritten later per-environment.
- load File.join(Rails.root.to_s, 'config', "settings", "application.rb"), :if_exists? => true
+ load File.join(Rails.root.to_s, "config", "settings", "application.rb"), :if_exists? => true
# Per Environment settings.
# At startup only the file matching current environment will be loaded.
# Settings stored here will overwrite settings with the same name stored in application.rb
- load File.join(Rails.root.to_s, 'config', "settings", "#{RAILS_ENV}.rb"), :if_exists? => true
+ load File.join(Rails.root.to_s, "config", "settings", "#{Rails.env}.rb"), :if_exists? => true
# Local settings. It is designed as a place for you to override variables
# specific to your own development environment.
# Make sure your version control system ignores this file otherwise
# you risk checking in a file that will override values in production
- load File.join(Rails.root.to_s, 'config', "settings", "local.rb"), :if_exists? => true
+ load File.join(Rails.root.to_s, "config", "settings", "local.rb"), :if_exists? => true
end

0 comments on commit 2773b63

Please sign in to comment.