configs 0.1.1 → 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03ad3dd99c10c113f0d632e6ee132f3f0e0ef2bd
4
+ data.tar.gz: a5a94f92eb7c08db2674e6fdfb221b5c59000580
5
+ SHA512:
6
+ metadata.gz: d4eda53c5625bc9d4250591033fb692efc8226a2dea903fcc55283790fee5ac0103134d86eeae7724ccd6aaa58791def16c1124f291d0ebafefbb1413babc60a
7
+ data.tar.gz: f499c82d16e598d6a4abcfbd4d8eef64394a6bd77f74427c816849717dc4fd1f4be81ce55c40737eb17b13b8307e4416752b320df1502504749a8bee25b0b491
@@ -1,6 +1,9 @@
1
+ require "yaml"
1
2
  require "configs/version"
2
3
  require "configs/railtie" if defined? Rails
3
4
 
5
+ require 'active_support/core_ext/hash/indifferent_access'
6
+
4
7
  module Configs
5
8
  class NotFound < StandardError;
6
9
  def initialize(name, env)
@@ -25,13 +28,17 @@ module Configs
25
28
  # if none can be found, it will raise an error
26
29
  def [](name)
27
30
  @_configs ||= {}
28
- @_configs[name.to_sym] ||= load(name).symbolize_keys
31
+ @_configs[name.to_sym] ||= load(name)
29
32
  end
30
33
 
31
34
  def inspect
32
35
  @_configs.inspect
33
36
  end
34
37
 
38
+ def reload
39
+ @_configs = {}
40
+ end
41
+
35
42
  protected
36
43
 
37
44
  # checks loading order for named yml file
@@ -49,7 +56,7 @@ module Configs
49
56
 
50
57
  def yml_file(name)
51
58
  path = config_dir.join(name + '.yml')
52
- YAML.load_file path if File.exists? path
59
+ YAML.load_file(path).with_indifferent_access if File.exists? path
53
60
  end
54
61
 
55
62
  def yml_file_with_key(path, key)
@@ -58,4 +65,4 @@ module Configs
58
65
  end
59
66
 
60
67
  end
61
- end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Configs
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,6 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
2
 
3
3
  class ConfigsTest < Configs::TestCase
4
+ def setup
5
+ Configs.reload
6
+ end
4
7
 
5
8
  should "find config/foo/test.yml" do
6
9
  with_config('foo/test.yml', :hello => 'world') do
@@ -9,6 +12,12 @@ class ConfigsTest < Configs::TestCase
9
12
  end
10
13
 
11
14
  should "find config/foo.yml with test key" do
15
+ with_config('foo.yml', 'test' => {:hello => 'world'}) do
16
+ assert_equal 'world', Configs[:foo][:hello]
17
+ end
18
+ end
19
+
20
+ should "find config/foo.yml with :test key" do
12
21
  with_config('foo.yml', :test => {:hello => 'world'}) do
13
22
  assert_equal 'world', Configs[:foo][:hello]
14
23
  end
@@ -20,7 +29,13 @@ class ConfigsTest < Configs::TestCase
20
29
  end
21
30
  end
22
31
 
23
- should "find config/foo.yml with 'default' key" do
32
+ should "find config/foo.yml with default key" do
33
+ with_config('foo.yml', 'default' => {:hello => 'world'}) do
34
+ assert_equal 'world', Configs[:foo][:hello]
35
+ end
36
+ end
37
+
38
+ should "find config/foo.yml with :default key" do
24
39
  with_config('foo.yml', :default => {:hello => 'world'}) do
25
40
  assert_equal 'world', Configs[:foo][:hello]
26
41
  end
@@ -30,9 +45,10 @@ class ConfigsTest < Configs::TestCase
30
45
  assert_raises(Configs::NotFound) { Configs[:unknown] }
31
46
  end
32
47
 
33
- should "symbolize keys" do
34
- with_config('foo.yml', :test => {'hello' => 'world'}) do
48
+ should "support indifferent hash access" do
49
+ with_config('foo.yml', 'test' => {:hello => 'world'}) do
35
50
  assert_equal 'world', Configs[:foo][:hello]
51
+ assert_equal 'world', Configs[:foo]['hello']
36
52
  end
37
53
  end
38
54
 
@@ -48,4 +64,4 @@ class ConfigsTest < Configs::TestCase
48
64
  File.delete(path)
49
65
  end
50
66
  end
51
- end
67
+ end
@@ -3,15 +3,14 @@ require 'bundler'
3
3
  Bundler.require(:default, :test)
4
4
 
5
5
  require 'test/unit'
6
- require 'active_support/core_ext/hash/keys'
7
6
 
8
7
  class Configs::TestCase < Test::Unit::TestCase
9
8
  def default_test; end # quiet Test::Unit
10
9
 
11
10
  def self.should(name, &block) # very simple syntax
12
- define_method("test_should_#{name.gsub(/[ -\/]/, '_').gsub(/[^a-z0-9_]/i, '')}", &block)
11
+ define_method("test_should_#{name.gsub(/[ -\/]/, '_').gsub(/[^a-z0-9_]/i, '_')}", &block)
13
12
  end
14
13
  end
15
14
 
16
15
  Configs.config_dir = Pathname.new(File.dirname(__FILE__) + '/config')
17
- Configs.environment = 'test'
16
+ Configs.environment = 'test'
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lance Ivy
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
11
+ date: 2013-07-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
- requirement: &70185842205240 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>'
17
+ - - '>'
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70185842205240
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>'
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: test-unit
27
- requirement: &70185842203740 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70185842203740
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  description: Easy (easier?) management of config/*.yml files. Defines a lookup priority
37
42
  for the current environment's settings.
38
43
  email:
@@ -54,29 +59,27 @@ files:
54
59
  - test/test_helper.rb
55
60
  homepage: http://github.com/kickstarter/configs
56
61
  licenses: []
62
+ metadata: {}
57
63
  post_install_message:
58
64
  rdoc_options: []
59
65
  require_paths:
60
66
  - lib
61
67
  required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
68
  requirements:
64
- - - ! '>='
69
+ - - '>='
65
70
  - !ruby/object:Gem::Version
66
71
  version: '0'
67
72
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
73
  requirements:
70
- - - ! '>='
74
+ - - '>='
71
75
  - !ruby/object:Gem::Version
72
76
  version: '0'
73
77
  requirements: []
74
78
  rubyforge_project:
75
- rubygems_version: 1.8.11
79
+ rubygems_version: 2.0.0
76
80
  signing_key:
77
- specification_version: 3
81
+ specification_version: 4
78
82
  summary: Easy (easier?) management of config/*.yml files.
79
83
  test_files:
80
84
  - test/configs_test.rb
81
85
  - test/test_helper.rb
82
- has_rdoc: