forked from markbates/configatron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Configatron::Rails.init helper method and ConfigatronGenerator …
…for generating configatron files for Rails.
- Loading branch information
Showing
14 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rails_generator' | ||
class ConfigatronGenerator < Rails::Generator::Base # :nodoc: | ||
|
||
def manifest | ||
record do |m| | ||
m.directory 'config/configatron' | ||
m.directory 'config/configatron/development' | ||
m.directory 'config/configatron/test' | ||
m.directory 'config/configatron/production' | ||
m.directory 'config/configatron/cucumber' | ||
m.file 'initializers/configatron.rb', 'config/initializers/configatron.rb' | ||
m.file 'configatron/development.rb', 'config/configatron/development.rb' | ||
m.file 'configatron/production.rb', 'config/configatron/production.rb' | ||
m.file 'configatron/test.rb', 'config/configatron/test.rb' | ||
m.file 'configatron/cucumber.rb', 'config/configatron/cucumber.rb' | ||
m.file 'configatron/defaults.rb', 'config/configatron/defaults.rb' | ||
end | ||
end | ||
|
||
end # ConfigatronGenerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Override your default settings for the Cucumber environment here. | ||
|
||
# By default load in the settings from the test environment: | ||
require File.join(File.dirname(__FILE__), 'test') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Put all your default configatron settings here. | ||
|
||
# Example: | ||
# configatron.emails.welcome.subject = 'Welcome!' | ||
# configatron.emails.sales_reciept.subject = 'Thanks for your order' | ||
# | ||
# configatron.file.storage = :s3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Override your default settings for the Development environment here. | ||
# | ||
# Example: | ||
# configatron.file.storage = :local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Override your default settings for the Production environment here. | ||
# | ||
# Example: | ||
# configatron.file.storage = :s3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Override your default settings for the Test environment here. | ||
# | ||
# Example: | ||
# configatron.file.storage = :local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'configatron' | ||
Configatron::Rails.init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Configatron | ||
# Helpful for making using configatron with Rails even easier! | ||
# | ||
# To get started you can use the generator to generate | ||
# the necessary stub files. | ||
# | ||
# $ ruby script/generate configatron | ||
module Rails | ||
|
||
# Loads configatron files in the following order: | ||
# | ||
# Example: | ||
# <RAILS_ROOT>/config/configatron/defaults.rb | ||
# <RAILS_ROOT>/config/configatron/<RAILS_ENV>.rb | ||
# # optional: | ||
# <RAILS_ROOT>/config/configatron/<RAILS_ENV>/defaults.rb | ||
# <RAILS_ROOT>/config/configatron/<RAILS_ENV>/bar.rb | ||
# <RAILS_ROOT>/config/configatron/<RAILS_ENV>/foo.rb | ||
def self.init | ||
config_files = [] | ||
|
||
base_dir = File.expand_path(File.join(RAILS_ROOT, 'config', 'configatron')) | ||
config_files << File.join(base_dir, 'defaults.rb') | ||
config_files << File.join(base_dir, "#{RAILS_ENV}.rb") | ||
|
||
env_dir = File.join(base_dir, RAILS_ENV) | ||
config_files << File.join(env_dir, 'defaults.rb') | ||
|
||
Dir.glob(File.join(env_dir, '*.rb')).sort.each do |f| | ||
config_files << f | ||
end | ||
|
||
config_files.collect! {|config| File.expand_path(config)}.uniq! | ||
|
||
config_files.each do |config| | ||
if File.exists?(config) | ||
# puts "Configuration: #{config}" | ||
require config | ||
end | ||
end | ||
end | ||
|
||
end # Rails | ||
end # Configatron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
|
||
describe Configatron::Rails do | ||
|
||
%w{development test production cucumber}.each do |env| | ||
|
||
describe env do | ||
|
||
before(:each) do | ||
Object.send(:remove_const, 'RAILS_ENV') rescue nil | ||
Object.send(:remove_const, 'RAILS_ROOT') rescue nil | ||
RAILS_ENV = env | ||
RAILS_ROOT = File.join(File.dirname(__FILE__), '..', "tmp_rails_root_#{env}") | ||
@configatron_path = File.join(RAILS_ROOT, 'config', 'configatron') | ||
@defaults_file_loc = File.join(@configatron_path, 'defaults.rb') | ||
@env_file_loc = File.join(@configatron_path, "#{env}.rb") | ||
@env_folder_loc = File.join(@configatron_path, env) | ||
@env_bar_loc = File.join(@env_folder_loc, 'bar.rb') | ||
@env_foo_loc = File.join(@env_folder_loc, 'foo.rb') | ||
|
||
FileUtils.mkdir_p(@env_folder_loc) | ||
|
||
File.open(@defaults_file_loc, 'w') do |f| | ||
f.puts 'configatron.fooa = :foo' | ||
f.puts 'configatron.bara = :bar' | ||
f.puts 'configatron.env = :default' | ||
f.puts 'configatron.something.else = 1' | ||
f.puts 'configatron.and.another.thing = 42' | ||
end | ||
|
||
File.open(@env_file_loc, 'w') do |f| | ||
f.puts "configatron.env = :#{env}" | ||
f.puts 'configatron.something.else = 2' | ||
end | ||
|
||
File.open(@env_bar_loc, 'w') do |f| | ||
f.puts "configatron.bara = 'BAR!!'" | ||
f.puts 'configatron.something.else = 3' | ||
end | ||
|
||
File.open(@env_foo_loc, 'w') do |f| | ||
f.puts "configatron.fooa = :fubar" | ||
f.puts 'configatron.something.else = 4' | ||
end | ||
end | ||
|
||
after(:each) do | ||
FileUtils.rm_rf(RAILS_ROOT) | ||
Object.send(:remove_const, 'RAILS_ENV') | ||
Object.send(:remove_const, 'RAILS_ROOT') | ||
# configatron.reset! | ||
end | ||
|
||
it 'should read the defaults first and then the env file' do | ||
Configatron::Rails.init | ||
configatron.fooa.should == :fubar | ||
configatron.bara.should == 'BAR!!' | ||
configatron.env.should == env.to_sym | ||
configatron.something.else.should == 4 | ||
configatron.and.another.thing.should == 42 | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |