Skip to content

Commit

Permalink
Merge remote branch 'source/master'
Browse files Browse the repository at this point in the history
Fixed conflicts in:
	lib/rails_config/railtie.rb
  • Loading branch information
cryo28 committed May 17, 2011
2 parents dc248a9 + 777acd3 commit 900d855
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 37 deletions.
5 changes: 2 additions & 3 deletions Gemfile.lock
@@ -1,13 +1,13 @@
PATH
remote: .
specs:
rails_config (0.2.0)
rails_config (0.2.3)
activesupport (~> 3.0)

GEM
remote: http://rubygems.org/
specs:
activesupport (3.0.2)
activesupport (3.0.6)
archive-tar-minitar (0.5.2)
autotest (4.4.3)
columnize (0.3.2)
Expand Down Expand Up @@ -44,7 +44,6 @@ PLATFORMS
ruby

DEPENDENCIES
activesupport (~> 3.0)
autotest
growl-glue
rails_config!
Expand Down
30 changes: 30 additions & 0 deletions README.md
Expand Up @@ -14,6 +14,8 @@ RailsConfig helps you easily manage environment specific Rails settings in an ea
## Compatibility

* Rails 3.0
* Padrino
* Sinatra

For older versions of Rails and other Ruby apps, use [AppConfig](http://github.com/fredwu/app_config).

Expand All @@ -23,6 +25,34 @@ Add this to your `Gemfile`:

gem "rails_config"


## Installing on Padrino

Add this to your `Gemfile`:

gem "rails_config"

in your app.rb, you'll also need to register RailsConfig

register RailsConfig


## Installing on Sinatra

Add this to your `Gemfile`:

gem "rails_config"

in your app, you'll need to register RailsConfig. You'll also need to give it a root so it can find the config files.

set :root, File.dirname(__FILE__)
register RailsConfig

It's also possible to initialize it manually within your configure block if you want to just give it some yml paths to load from.

RailsConfig.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)


## Customizing RailsConfig

You may customize the behavior of RailsConfig by generating an initializer file:
Expand Down
11 changes: 9 additions & 2 deletions lib/rails_config.rb
Expand Up @@ -36,7 +36,14 @@ def self.load_and_set_settings(*files)
Kernel.send(:remove_const, RailsConfig.const_name) if Kernel.const_defined?(RailsConfig.const_name)
Kernel.const_set(RailsConfig.const_name, RailsConfig.load_files(files))
end

def self.reload!
Kernel.const_get(RailsConfig.const_name).reload!
end
end

# add railtie
require 'rails_config/railtie'
# add rails integration
require('rails_config/integration/rails') if defined?(::Rails)

# add sinatra integration
require('rails_config/integration/sinatra') if defined?(::Sinatra)
33 changes: 33 additions & 0 deletions lib/rails_config/integration/rails.rb
@@ -0,0 +1,33 @@
module RailsConfig
module Integration
module Rails3
if defined?(Rails::Railtie)
class Railtie < Rails::Railtie

# manually load the custom initializer before everything else
initializer :load_custom_rails_config, :before => :bootstrap_hook do
initializer = Rails.root.join("config", "initializers", "rails_config")
require initializer if File.exist?(initializer)
end

# Parse the settings before any of the initializers
ActiveSupport.on_load :before_configuration, :yield => true do
RailsConfig.load_and_set_settings(
Rails.root.join("config", "settings.yml").to_s,
Rails.root.join("config", "settings.local.yml").to_s
)
end

# Rails Dev environment should reload the Settings on every request
if Rails.env.development?
initializer :rails_config_reload_on_development do
ActionController::Base.class_eval do
prepend_before_filter { ::RailsConfig.const_name.constantize.reload! }
end
end
end
end
end
end
end
end
31 changes: 31 additions & 0 deletions lib/rails_config/integration/sinatra.rb
@@ -0,0 +1,31 @@
require "rails_config/rack/reloader"

module RailsConfig
# provide helper to register within your Sinatra app
#
# set :root, File.dirname(__FILE__)
# register RailsConfig
#
def self.registered(app)
app.configure do |inner_app|

env = inner_app.environment || ENV["RACK_ENV"]
root = inner_app.root

# use Padrino settings if applicable
if defined?(Padrino)
env = Padrino.env
root = Padrino.root
end

RailsConfig.load_and_set_settings(
File.join(root.to_s, "config", "settings.yml").to_s,
File.join(root.to_s, "config", "settings", "#{env}.yml").to_s,
File.join(root.to_s, "config", "environments", "#{env}.yml").to_s
)

inner_app.use(::RailsConfig::Rack::Reloader) if inner_app.development?
end
end

end
15 changes: 15 additions & 0 deletions lib/rails_config/rack/reloader.rb
@@ -0,0 +1,15 @@
module RailsConfig
module Rack
# Rack middleware the reloads RailsConfig on every request (only use in dev mode)
class Reloader
def initialize(app)
@app = app
end

def call(env)
RailsConfig.reload!
@app.call(env)
end
end
end
end
30 changes: 0 additions & 30 deletions lib/rails_config/railtie.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/rails_config/version.rb
@@ -1,3 +1,3 @@
module RailsConfig
VERSION = "0.2.1"
VERSION = "0.2.3"
end
2 changes: 1 addition & 1 deletion rails_config.gemspec
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }

s.add_runtime_dependency "activesupport", "~> 3.0"
s.add_runtime_dependency "activesupport", ">= 3.0"
s.add_development_dependency "rspec", "~> 2.0"
s.add_development_dependency "autotest", ">= 0"
s.add_development_dependency "growl-glue", ">= 0"
Expand Down

0 comments on commit 900d855

Please sign in to comment.