Skip to content

Commit

Permalink
simplified Gems -- Loads fewer things by default. using multi_json, w…
Browse files Browse the repository at this point in the history
…ith (preferred but optional) Oj. Added Guardfile.
  • Loading branch information
Philip (flip) Kromer committed Jun 18, 2012
1 parent 5ed9f8d commit 436f902
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format documentation
6 changes: 2 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
source "http://rubygems.org"

gem 'multi_json', "~> 1.1"
gem 'yajl-ruby', "~> 1.1", :platform => :mri
gem 'json', :platform => :jruby
gem 'oj', "~> 1.2.9"
gem 'json', :platform => :jruby

# Only necessary if you want to use Configliere::Prompt
gem 'highline', ">= 1.5.2"


group :development do
gem 'bundler', "~> 1"
gem 'jeweler', "~> 1.6"
Expand All @@ -21,7 +20,6 @@ group :docs do
end

group :test do
gem 'spork', "~> 0.9.0.rc5"
gem 'rspec', "~> 2.8"
gem 'guard', ">= 1.0"
gem 'guard-rspec', ">= 0.6"
Expand Down
14 changes: 14 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- ruby -*-

format = 'progress' # 'doc' for more verbose, 'progress' for less
tags = %w[ ] # builder_spec model_spec

guard 'rspec', :version => 2, :cli => "--format #{format} #{ tags.map{|tag| "--tag #{tag}"}.join(' ') }" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^examples/(\w+)/(.+)\.rb$}) { |m| "spec/examples/#{m[1]}_spec.rb" }
watch(%r{^examples/(\w+)\.rb$}) { |m| "spec/examples/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
watch(%r{^lib/(\w+)\.rb$}) { |m| "spec/#{m[1]}}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
watch(/spec\/support\/(.+)\.rb/) { 'spec' }
end
1 change: 0 additions & 1 deletion lib/configliere.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'date' # type conversion
require 'time' # type conversion
require 'yaml' # read files
require 'fileutils' # so save! can mkdir
require 'configliere/deep_hash' # magic hash for params
require 'configliere/param' # params container
Expand Down
5 changes: 3 additions & 2 deletions lib/configliere/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def read filename, options={}
case filetype(filename)
when 'json' then read_json(File.open(filename), options)
when 'yaml' then read_yaml(File.open(filename), options)
else read_yaml(File.open(filename), options)
else read_yaml(File.open(filename), options)
end
rescue Errno::ENOENT => e
warn "Loading empty configliere settings file #{filename}"
Expand All @@ -56,7 +56,8 @@ def read_yaml yaml_str, options={}
# we depend on you to require some sort of JSON
#
def read_json json_str, options={}
new_data = JSON.load(json_str) || {}
require 'multi_json'
new_data = MultiJson.load(json_str) || {}
# Extract the :env (production/development/etc)
if options[:env]
new_data = new_data[options[:env]] || {}
Expand Down
2 changes: 1 addition & 1 deletion spec/configliere/config_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

describe 'loading a yaml config file' do
before do
@fake_file = '{ :my_param: val_from_file }'
@fake_file = "---\nmy_param: val_from_file"
end

describe 'successfully' do
Expand Down
2 changes: 1 addition & 1 deletion spec/configliere_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
end

it 'requires corresponding plugins when you call use' do
lambda{ Configliere.use(:param, :foo) }.should raise_error(LoadError, 'no such file to load -- configliere/foo')
lambda{ Configliere.use(:param, :foo) }.should raise_error(LoadError, /no.*load.*configliere\/foo/)
end
end
23 changes: 4 additions & 19 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
# encoding: UTF-8
require 'rubygems'
require 'spork'
require 'rubygems' unless defined?(Gem)
require 'rspec'

Spork.prefork do
# Loading more in this block will cause your tests to run faster.
# However, changes don't take effect until you restart spork.

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'configliere'

RSpec.configure do |config|
end
end

Spork.each_run do
# This code will be run each time you run your specs.

end
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'configliere'

0 comments on commit 436f902

Please sign in to comment.