Permalink
Browse files

Merge branch 'add_to_hash_support' of https://github.com/kris/rails_c…

…onfig into kris-add_to_hash_support

Conflicts:
  rails_config.gemspec
  • Loading branch information...
2 parents dfa1da7 + 44f18af commit e25565ccfd7d161e9ff554a3b8b52707593ed88b @jacquescrocker jacquescrocker committed Nov 17, 2010
Showing with 66 additions and 82 deletions.
  1. +4 −5 Gemfile
  2. +15 −17 Gemfile.lock
  3. +6 −21 Rakefile
  4. +0 −8 TODO
  5. +14 −0 lib/rails_config/options.rb
  6. +1 −1 lib/rails_config/railtie.rb
  7. +3 −0 lib/rails_config/version.rb
  8. +18 −30 rails_config.gemspec
  9. +5 −0 spec/rails_config_spec.rb
View
@@ -2,8 +2,7 @@ source 'http://rubygems.org'
gemspec
-gem "ruby-debug", :platforms => :mri_18
-gem "ruby-debug19", :platforms => :mri_19
-
-gem "autotest", ">= 0"
-gem "growl-glue", ">= 0"
+group :development do
+ gem "ruby-debug", :platforms => :mri_18
+ gem "ruby-debug19", :platforms => :mri_19
+end
View
@@ -1,35 +1,33 @@
PATH
remote: .
specs:
- rails_config (0.1.7)
+ rails_config (0.2.0)
activesupport (~> 3.0)
GEM
remote: http://rubygems.org/
specs:
- activesupport (3.0.0)
+ activesupport (3.0.2)
archive-tar-minitar (0.5.2)
- autotest (4.3.2)
- columnize (0.3.1)
+ autotest (4.4.3)
+ columnize (0.3.2)
diff-lcs (1.1.2)
growl-glue (1.0.7)
linecache (0.43)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
- rspec (2.0.0)
- rspec-core (= 2.0.0)
- rspec-expectations (= 2.0.0)
- rspec-mocks (= 2.0.0)
- rspec-core (2.0.0)
- rspec-expectations (2.0.0)
- diff-lcs (>= 1.1.2)
- rspec-mocks (2.0.0)
- rspec-core (= 2.0.0)
- rspec-expectations (= 2.0.0)
- ruby-debug (0.10.3)
+ rspec (2.1.0)
+ rspec-core (~> 2.1.0)
+ rspec-expectations (~> 2.1.0)
+ rspec-mocks (~> 2.1.0)
+ rspec-core (2.1.0)
+ rspec-expectations (2.1.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.1.0)
+ ruby-debug (0.10.4)
columnize (>= 0.1)
- ruby-debug-base (~> 0.10.3.0)
- ruby-debug-base (0.10.3)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
View
@@ -1,24 +1,10 @@
-require "bundler"
-Bundler.setup
-
-require 'rake'
-require 'rake/gempackagetask'
-
-gemspec = eval(File.read('rails_config.gemspec'))
-Rake::GemPackageTask.new(gemspec) do |pkg|
- pkg.gem_spec = gemspec
-end
-
-desc "build the gem and release it to rubygems.org"
-task :release => :gem do
- puts "Tagging #{gemspec.version}..."
- system "git tag -a #{gemspec.version} -m 'Tagging #{gemspec.version}'"
- puts "Pushing to Github..."
- system "git push --tags"
- puts "Pushing to rubygems.org..."
- system "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
+begin
+ require "bundler"
+ Bundler::GemHelper.install_tasks
+rescue Exception => e
end
+require "rake"
require "rspec"
require "rspec/core/rake_task"
@@ -34,10 +20,9 @@ end
require "rake/rdoctask"
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = "rdoc"
- rdoc.title = "Rails Config #{gemspec.version}"
+ rdoc.title = "Rails Config #{RailsConfig::VERSION}"
rdoc.rdoc_files.include("README*")
rdoc.rdoc_files.include("lib/**/*.rb")
end
-
task :default => :spec
View
8 TODO
@@ -1,8 +0,0 @@
-- Change part of the install generator to `rails_config:override` that creates an config/rails_config.rb initializer and disables the default initialzer
-
-DONE:
-- Add a Rails before_filter that triggers Settings.reload! for each development request
-- Add generator `rails_config:install` to create the default setting files
-- Allow user to customize the name of the global setting object (Settings)
-- Abstract OpenStruct to RailsConfig::Options
-- Add ability to define multiple sources (Start with YAMLSource)
@@ -32,6 +32,20 @@ def reload!
return self
end
+
+ # Dump openstruct to a hash
+ def to_hash
+ result = {}
+ @table.each do |k, v|
+ key = k.to_sym
+ if v.instance_of?(RailsConfig::Options)
+ result[key] = v.to_hash
+ else
+ result[key] = v
+ end
+ end
+ result
+ end
alias :load! :reload!
@@ -21,7 +21,7 @@ class Railtie < Rails::Railtie
if Rails.env.development?
initializer :rails_config_reload_on_development do
ActionController::Base.class_eval do
- prepend_before_filter { ::Settings.reload! }
+ prepend_before_filter { ::RailsConfig.const_name.constantize.reload! }
end
end
end
@@ -0,0 +1,3 @@
+module RailsConfig
+ VERSION = "0.2.0"
+end
View
@@ -1,36 +1,24 @@
-Gem::Specification.new do |s|
- s.name = "rails_config"
- s.version = "0.1.8"
-
- s.authors = ["Jacques Crocker", "Fred Wu"]
- s.summary = "Provides a Settings helper for rails3 that reads from config/settings.yml"
- s.description = "Easy to use Settings helper that loads its data in from config/settings.yml. Handles adding multiple sources, and easy reloading."
-
- s.email = ["railsjedi@gmail.com", "ifredwu@gmail.com"]
- s.homepage = "http://github.com/railsjedi/rails_config"
- s.rubyforge_project = "none"
+require File.dirname(__FILE__) + "/lib/rails_config/version"
- s.require_paths = ["lib"]
- s.files = Dir['lib/**/*',
- 'spec/**/*',
- 'rails_config.gemspec',
- 'Gemfile',
- 'Gemfile.lock',
- 'LICENSE',
- 'Rakefile',
- 'README.md',
- 'TODO']
-
- s.test_files = Dir['spec/**/*']
- s.rdoc_options = ["--charset=UTF-8"]
- s.extra_rdoc_files = [
- "LICENSE",
- "README.md",
- "TODO"
- ]
+Gem::Specification.new do |s|
+ s.name = "rails_config"
+ s.version = RailsConfig::VERSION
+ s.date = Date.today.to_s
+ s.authors = ["Jacques Crocker", "Fred Wu"]
+ s.email = ["railsjedi@gmail.com", "ifredwu@gmail.com"]
+ s.summary = "Provides a Settings helper for rails3 that reads from config/settings.yml"
+ s.description = "Easy to use Settings helper that loads its data in from config/settings.yml. Handles adding multiple sources, and easy reloading."
+ s.homepage = "http://github.com/railsjedi/rails_config"
+ s.extra_rdoc_files = ["README.md"]
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.files = `git ls-files`.split("\n")
+ 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_development_dependency "rspec", "~> 2.0"
-
+ s.add_development_dependency "autotest", ">= 0"
+ s.add_development_dependency "growl-glue", ">= 0"
end
@@ -30,6 +30,11 @@
config = RailsConfig.load_files(setting_path("empty1.yml"))
config.should be_empty
end
+
+ it "should convert to a hash" do
+ config = RailsConfig.load_files(setting_path("development.yml"))
+ config.to_hash[:section][:servers].should be_a_kind_of(Array)
+ end
it "should load an empty config for multiple missing file paths" do
files = [setting_path("empty1.yml"), setting_path("empty2.yml")]

0 comments on commit e25565c

Please sign in to comment.