config_reader 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in config_reader.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ config_reader (0.0.9)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ rake (0.9.2.2)
10
+ rspec (1.3.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ config_reader!
17
+ rake
18
+ rspec (= 1.3.2)
@@ -1,3 +1,11 @@
1
+ == 0.0.9 2012-02-03
2
+ * Stop abusing Hash, it's not nice
3
+ * convert all keys to symbols internally
4
+ * move to a bundler style gem
5
+
6
+ == 0.0.8 2011-05-12
7
+ * Silence RAILS_ENV deprecation, thanks jeanmartin
8
+
1
9
  == 0.0.7 2010-02-14
2
10
  * moved to jeweler
3
11
  * removed the annoying post install message
@@ -18,7 +26,7 @@
18
26
  * fix the environment merging issue
19
27
 
20
28
  == 0.0.2 2008-09-10
21
- * have find_config return the file if it exists instead of looking in . and
29
+ * have find_config return the file if it exists instead of looking in . and
22
30
  ./config
23
31
 
24
32
  == 0.0.1 2008-08-06
data/License.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 FIXME full name
1
+ Copyright (c) 2008 Michael Moen
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,29 +1,4 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "config_reader"
8
- gem.summary = %Q{Provides a way to manage environment specific configuration settings.}
9
- gem.description = %Q{Provides a way to manage environment specific configuration settings.}
10
- gem.email = "michael@underpantsgnome.com"
11
- gem.homepage = "http://github.com/UnderpantsGnome/config_reader-gem"
12
- gem.authors = ["Michael Moen"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
26
- end
1
+ require "bundler/gem_tasks"
27
2
 
28
3
  require 'spec/rake/spectask'
29
4
  Spec::Rake::SpecTask.new(:spec) do |spec|
@@ -31,22 +6,4 @@ Spec::Rake::SpecTask.new(:spec) do |spec|
31
6
  spec.spec_files = FileList['spec/**/*_spec.rb']
32
7
  end
33
8
 
34
- Spec::Rake::SpecTask.new(:rcov) do |spec|
35
- spec.libs << 'lib' << 'spec'
36
- spec.pattern = 'spec/**/*_spec.rb'
37
- spec.rcov = true
38
- end
39
-
40
- task :spec => :check_dependencies
41
-
42
9
  task :default => :spec
43
-
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "temp #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
@@ -1,54 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "config_reader/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{config_reader}
8
- s.version = "0.0.8"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Moen"]
12
- s.date = %q{2011-05-12}
6
+ s.name = "config_reader"
7
+ s.version = ConfigReader::VERSION
8
+ s.authors = ["Michael Moen"]
9
+ s.email = ["michael@underpantsgnome.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Provides a way to manage environment specific configuration settings.}
13
12
  s.description = %q{Provides a way to manage environment specific configuration settings.}
14
- s.email = %q{michael@underpantsgnome.com}
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- "History.txt",
20
- "License.txt",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "config_reader.gemspec",
25
- "lib/config_reader.rb",
26
- "spec/config_reader_spec.rb",
27
- "spec/spec.opts",
28
- "spec/spec_helper.rb",
29
- "spec/test_config.rb",
30
- "spec/test_config.yml"
31
- ]
32
- s.homepage = %q{http://github.com/UnderpantsGnome/config_reader-gem}
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.7.2}
35
- s.summary = %q{Provides a way to manage environment specific configuration settings.}
36
- s.test_files = [
37
- "spec/config_reader_spec.rb",
38
- "spec/spec_helper.rb",
39
- "spec/test_config.rb"
40
- ]
41
13
 
42
- if s.respond_to? :specification_version then
43
- s.specification_version = 3
14
+ s.rubyforge_project = "config_reader"
44
15
 
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
47
- else
48
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
49
- end
50
- else
51
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
- end
53
- end
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
54
20
 
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "rspec", "1.3.2"
24
+ end
@@ -0,0 +1,29 @@
1
+ class ConfigReader
2
+ class MagicHash < Hash
3
+
4
+ def self.convert_hash(hash)
5
+ magic_hash = new
6
+
7
+ hash.each_pair do |key, value|
8
+ if value.is_a?(Hash)
9
+ magic_hash[key.to_sym] = convert_hash(value)
10
+ else
11
+ magic_hash[key.to_sym] = value
12
+ end
13
+ end
14
+
15
+ magic_hash
16
+ end
17
+
18
+ def [](key)
19
+ fetch(key.to_sym)
20
+ end
21
+
22
+ def method_missing(key)
23
+ has_key?(key) ?
24
+ fetch(key) :
25
+ super
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ class ConfigReader
2
+ VERSION = "0.0.9"
3
+ end
data/lib/config_reader.rb CHANGED
@@ -1,4 +1,7 @@
1
+ require "config_reader/version"
2
+ require "config_reader/magic_hash"
1
3
  require 'yaml'
4
+
2
5
  begin
3
6
  require 'erb'
4
7
  rescue LoadError
@@ -40,11 +43,11 @@ class ConfigReader
40
43
 
41
44
  _conf = conf['defaults']
42
45
  _conf.merge!(conf[env]) if conf[env]
43
- _conf
46
+ ConfigReader::MagicHash.convert_hash(_conf)
44
47
  end
45
48
 
46
49
  def [](key)
47
- config[key] || config[key.to_s]
50
+ config[key.to_sym]
48
51
  end
49
52
 
50
53
  def find_config
@@ -58,7 +61,7 @@ class ConfigReader
58
61
  end
59
62
 
60
63
  def method_missing(key)
61
- config[key.to_s] || nil
64
+ config[key] || nil
62
65
  end
63
66
 
64
67
  def inspect
@@ -66,9 +69,3 @@ class ConfigReader
66
69
  end
67
70
  end
68
71
  end
69
-
70
- class Hash
71
- def method_missing(key)
72
- has_key?(key) || has_key?(key.to_s) ? self[key] || self[key.to_s] : super
73
- end
74
- end
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "ConfigReader" do
4
4
  describe "parsing a YAML file" do
5
5
  it "should find values with method_missing" do
6
6
  TestConfig.app_name.should == 'default_app'
7
7
  end
8
-
8
+
9
9
  it "should find values using [] and a string" do
10
10
  TestConfig['app_name'].should == 'default_app'
11
11
  end
@@ -18,6 +18,10 @@ describe "ConfigReader" do
18
18
  TestConfig.nested_key.value.should == 'test'
19
19
  end
20
20
 
21
+ it "should find nested values using [] and a symbol" do
22
+ TestConfig[:nested_key][:value].should == 'test'
23
+ end
24
+
21
25
  it "should find nested values using [] and a string" do
22
26
  TestConfig['nested_key']['value'].should == 'test'
23
27
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'spec'
4
- require 'spec/autorun'
4
+ # require 'spec/autorun'
5
5
  require 'config_reader'
6
- require 'spec/test_config'
6
+ require 'test_config'
7
7
 
8
8
  Spec::Runner.configure do |config|
9
-
9
+
10
10
  end
metadata CHANGED
@@ -1,93 +1,94 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: config_reader
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 8
10
- version: 0.0.8
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael Moen
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-12 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rspec
12
+ date: 2012-02-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70272720215240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *70272720215240
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70272720194600 !ruby/object:Gem::Requirement
24
28
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 13
29
- segments:
30
- - 1
31
- - 2
32
- - 9
33
- version: 1.2.9
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.2
34
33
  type: :development
35
- version_requirements: *id001
34
+ prerelease: false
35
+ version_requirements: *70272720194600
36
36
  description: Provides a way to manage environment specific configuration settings.
37
- email: michael@underpantsgnome.com
37
+ email:
38
+ - michael@underpantsgnome.com
38
39
  executables: []
39
-
40
40
  extensions: []
41
-
42
- extra_rdoc_files:
43
- - README.rdoc
44
- files:
45
- - History.txt
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - History.rdoc
46
47
  - License.txt
47
48
  - README.rdoc
48
49
  - Rakefile
49
- - VERSION
50
50
  - config_reader.gemspec
51
51
  - lib/config_reader.rb
52
+ - lib/config_reader/magic_hash.rb
53
+ - lib/config_reader/version.rb
52
54
  - spec/config_reader_spec.rb
53
55
  - spec/spec.opts
54
56
  - spec/spec_helper.rb
55
57
  - spec/test_config.rb
56
58
  - spec/test_config.yml
57
- homepage: http://github.com/UnderpantsGnome/config_reader-gem
59
+ homepage: ''
58
60
  licenses: []
59
-
60
61
  post_install_message:
61
62
  rdoc_options: []
62
-
63
- require_paths:
63
+ require_paths:
64
64
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
66
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ segments:
72
72
  - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ hash: -4112497528289826160
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ segments:
81
81
  - 0
82
- version: "0"
82
+ hash: -4112497528289826160
83
83
  requirements: []
84
-
85
- rubyforge_project:
86
- rubygems_version: 1.7.2
84
+ rubyforge_project: config_reader
85
+ rubygems_version: 1.8.10
87
86
  signing_key:
88
87
  specification_version: 3
89
88
  summary: Provides a way to manage environment specific configuration settings.
90
- test_files:
89
+ test_files:
91
90
  - spec/config_reader_spec.rb
91
+ - spec/spec.opts
92
92
  - spec/spec_helper.rb
93
93
  - spec/test_config.rb
94
+ - spec/test_config.yml
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.8