Skip to content

Commit

Permalink
Converting to RSpec 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacques Crocker committed Aug 8, 2010
1 parent 66c7034 commit 3221dff
Show file tree
Hide file tree
Showing 26 changed files with 431 additions and 455 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'http://rubygems.org'

gem "rspec", ">= 2.0.0.beta.19"
gem 'autotest'
gem "growl-glue"

gem "ruby-debug"
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
GEM
remote: http://rubygems.org/
specs:
autotest (4.3.2)
columnize (0.3.1)
diff-lcs (1.1.2)
growl-glue (1.0.7)
linecache (0.43)
rspec (2.0.0.beta.19)
rspec-core (= 2.0.0.beta.19)
rspec-expectations (= 2.0.0.beta.19)
rspec-mocks (= 2.0.0.beta.19)
rspec-core (2.0.0.beta.19)
rspec-expectations (2.0.0.beta.19)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.19)
ruby-debug (0.10.3)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.3.0)
ruby-debug-base (0.10.3)
linecache (>= 0.3)

PLATFORMS
ruby

DEPENDENCIES
autotest
growl-glue
rspec (>= 2.0.0.beta.19)
ruby-debug
5 changes: 4 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ begin
s.homepage = "http://github.com/railsjedi/rails_config"
s.description = "Provides an easy to use Application Configuration object"
s.authors = ["Jacques Crocker"]
s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
s.files = FileList["[A-Z]*", "{bin,generators,lib,spec}/**/*"]

s.add_development_dependency 'rspec', ">=2.0.0.beta.19"

end
Jeweler::GemcutterTasks.new
rescue LoadError
Expand Down
2 changes: 2 additions & 0 deletions autotest/discover.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Autotest.add_discovery { "rspec2" }

5 changes: 3 additions & 2 deletions lib/rails_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rails_config/settings/deep_merge' unless defined?(DeepMerge)
require 'rails_config/settings/builder'
require 'rails_config/vendor/deep_merge' unless defined?(DeepMerge)
require 'pathname'

require 'rails_config/setting_builder'
require 'rails_config/railtie'
5 changes: 2 additions & 3 deletions lib/rails_config/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
module RailsConfig
class Railtie < Rails::Railtie
initializer :setup_rails_config do
::Settings = RailsConfig::Settings::Builder.load_files(
::Settings = RailsConfig::SettingBuilder.load_files(
:paths => [
Rails.root.join("config", "settings.yml").to_s,
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
],
:root_path => Rails.root
]
)
end
end
Expand Down
61 changes: 61 additions & 0 deletions lib/rails_config/setting_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'ostruct'
require 'yaml'
require 'erb'

module RailsConfig
module SettingBuilder
@@load_paths = []

# Create a config object (OpenStruct) from a yaml file. If a second yaml file is given, then the sections of that file will overwrite the sections
# if the first file if they exist in the first file.
def self.load_files(*files)
config = OpenStruct.new

@@load_paths = [files].flatten.compact.uniq
# add singleton method to our Settings that reloads its settings from the load_paths
def config.reload!

conf = {}
SettingBuilder.load_paths.to_a.each do |path|
file_conf = YAML.load(ERB.new(IO.read(path.to_s)).result) if path and File.exists?(path.to_s)
next unless file_conf

if conf.size > 0
DeepMerge.deep_merge!(file_conf, conf, :preserve_unmergeables => false)
else
conf = file_conf
end
end

# load all the new values into the openstruct
marshal_load(RailsConfig::SettingBuilder.convert(conf).marshal_dump)

return self
end

config.reload!
return config
end

def self.load_paths
@@load_paths
end

# Recursively converts Hashes to OpenStructs (including Hashes inside Arrays)
def self.convert(h) #:nodoc:
s = OpenStruct.new
h.each do |k, v|
s.new_ostruct_member(k)
if v.is_a?(Hash)
s.send( (k+'=').to_sym, convert(v))
elsif v.is_a?(Array)
converted_array = v.collect { |e| e.instance_of?(Hash) ? convert(e) : e }
s.send("#{k}=".to_sym, converted_array)
else
s.send("#{k}=".to_sym, v)
end
end
s
end
end
end
170 changes: 0 additions & 170 deletions lib/rails_config/settings/builder.rb

This file was deleted.

Loading

0 comments on commit 3221dff

Please sign in to comment.