config_yml 0.0.5 → 0.0.6

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5aa06e511ebafbb6657ccf82c486604df2ab9e7
4
+ data.tar.gz: 511f5a9adc69069ab065f75bf4324bc42b50284a
5
+ SHA512:
6
+ metadata.gz: a1265a4bbeb96eecc819e8ac95c467d66fc41444a029b4fe5591b3434d5a155da4ef7c0c62f7d3436b7eaf36868376754d5911d8ba0a9edfbf421121ed7f6e7b
7
+ data.tar.gz: d6c7bf958a61d6c63d82e0cf907754b201dde04b8d43fc835157681cbc96a98a482d87524dca14d9a3c101b7e6a6818c18c55dccd498842f8882f21563d4c9b8
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ - ruby-head
11
+ - jruby-head
12
+ - 1.8.7
13
+ - ree
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
- gem "rspec"
4
+ group :test do
5
+ gem "rake"
6
+ gem "rspec"
7
+ end
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- config_yml (0.0.5)
4
+ config_yml (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.2.4)
10
+ rake (10.0.4)
10
11
  rspec (2.13.0)
11
12
  rspec-core (~> 2.13.0)
12
13
  rspec-expectations (~> 2.13.0)
@@ -21,4 +22,5 @@ PLATFORMS
21
22
 
22
23
  DEPENDENCIES
23
24
  config_yml!
25
+ rake
24
26
  rspec
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  config_yml
2
2
  ==========
3
3
 
4
+ [![Build Status](https://travis-ci.org/vitork/config_yml.png?branch=master)](https://travis-ci.org/vitork/config_yml)
5
+ [![Code Climate](https://codeclimate.com/github/vitork/config_yml.png)](https://codeclimate.com/github/vitork/config_yml)
6
+
7
+
4
8
  Simplify your app configuration.
5
9
 
6
10
  Description
@@ -38,6 +42,9 @@ require "configuration"
38
42
  Usage
39
43
  -----
40
44
 
45
+ Create any yaml file inside config/ directory and it will became a hash accessible
46
+ through the class method with the same name of the file.
47
+
41
48
  ```yaml
42
49
  # config/redis.yml
43
50
  password: foo
@@ -58,9 +65,18 @@ ENV["REDIS_URL"] # => "redis://:foo@localhost:6379/1"
58
65
  You can also use the shorthand:
59
66
 
60
67
  ```ruby
61
- redis = Conf.redis
68
+ redis = Conf.redis # => { :password => "foo", :host => "localhost", :port => 6379, :database => 1 }
69
+ ```
70
+
71
+ To see all available yaml files:
72
+
73
+ ```ruby
74
+ Configuration.files # => ["config/redis.yml"]
62
75
  ```
63
76
 
77
+ Obs.: File names must match Ruby method name restrictions.
78
+ E.g. don't use config/my-app.yml, use config/my_app.yml instead.
79
+
64
80
  #### Environment based:
65
81
 
66
82
  ```yaml
@@ -111,13 +127,15 @@ foo:
111
127
  ```
112
128
 
113
129
  ```ruby
114
- Configuration.matryoshka[:foo][:bar][:baz] # => { :array => [:red, :green, :blue] }
130
+ Configuration.matryoshka[:foo][:bar][:baz][:array] # => [:red, :green, :blue]
115
131
  ```
116
132
 
117
133
  Manage yaml files
118
134
  -----------------
119
135
 
120
- Avoid maintain .yml files in your repository since they very ofter cointain sensitive information. You can use .yml.sample or .yml.example file instead with fake data.
136
+ Avoid maintain .yml files in your repository since they very ofter cointain
137
+ sensitive information. You can use .yml.sample or .yml.example files with fake
138
+ data instead.
121
139
 
122
140
  To transform sample files in yaml files, you can use the following task:
123
141
 
data/Rakefile CHANGED
@@ -2,3 +2,10 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "configuration/tasks"
5
+
6
+ task :default => :spec
7
+
8
+ desc "Run unit tests"
9
+ task :spec do
10
+ ruby "-S rspec"
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Configuration
2
- VERSION = "0.0.5".freeze
2
+ VERSION = "0.0.6".freeze
3
3
  end
data/lib/configuration.rb CHANGED
@@ -30,16 +30,16 @@ module Configuration
30
30
  @files ||= Dir.glob("config/*.yml")
31
31
  end
32
32
 
33
- def hash
34
- @hash ||= {}
35
- end
36
-
37
33
  def env
38
34
  @env ||= (ENV["RACK_ENV"] || Rails.env).to_sym rescue nil
39
35
  end
40
36
 
41
37
  private
42
38
 
39
+ def hash
40
+ @hash ||= {}
41
+ end
42
+
43
43
  def load_yml(file)
44
44
  config = with_symbol_keys YAML.load_file(file)
45
45
  config.is_a?(Hash) && config.has_key?(env) ?
@@ -50,7 +50,7 @@ module Configuration
50
50
  return hash_config unless hash_config.is_a?(Hash)
51
51
 
52
52
  hash_config.inject({}) do |symbolized, (key, value)|
53
- symbolized.merge({ key.to_sym => with_symbol_keys(value) })
53
+ symbolized.merge({ key.to_sym => with_symbol_keys(value), key => value })
54
54
  end
55
55
  end
56
56
  end
@@ -2,20 +2,20 @@ require "spec_helper"
2
2
 
3
3
  describe Configuration::Syntax::Conf do
4
4
  let(:files) { ["config/file_a.yml", "config/file_b.yml"] }
5
- let(:file_a) { { key_a: "value_a" } }
6
- let(:file_b) { { key_b: "value_b" } }
5
+ let(:file_a) { { "key_a" => "value_a" } }
6
+ let(:file_b) { { "key_b" => "value_b" } }
7
7
 
8
8
  before do
9
9
  Dir.stub(:glob).and_return(files)
10
10
  YAML.stub(:load_file).and_return(file_a, file_b)
11
11
  end
12
12
 
13
- it "provides an interface for access yml config files" do
13
+ it "provides an interface to access yml config files" do
14
14
  Conf.file_a[:key_a].should be_eql "value_a"
15
15
  Conf.file_b[:key_b].should be_eql "value_b"
16
16
  end
17
17
 
18
- it "doesn't provide an interface for access other attributes" do
18
+ it "doesn't provide an interface to access other attributes" do
19
19
  Conf.files.should_not be_eql files
20
20
  end
21
21
  end
@@ -57,29 +57,38 @@ describe Configuration do
57
57
 
58
58
  describe "acessing a key from configuration files" do
59
59
  context "when a file has a flat hash" do
60
- let(:file_a) { { key_a: "value_a" } }
61
- let(:file_b) { { key_b: "value_b" } }
60
+ let(:file_a) { { "key_a" => "value_a" } }
61
+ let(:file_b) { { "key_b" => "value_b" } }
62
62
 
63
- it "responds to keys split in different files" do
63
+ it "responds to symbol keys split in different files" do
64
64
  subject.file_a[:key_a].should be_eql "value_a"
65
65
  subject.file_b[:key_b].should be_eql "value_b"
66
66
  end
67
+
68
+ it "responds to string keys split in different files" do
69
+ subject.file_a["key_a"].should be_eql "value_a"
70
+ subject.file_b["key_b"].should be_eql "value_b"
71
+ end
67
72
  end
68
73
 
69
74
  context "when a file has a nested hash" do
70
- let(:file_a) { { nested: { key: "value" } } }
75
+ let(:file_a) { { "nested" => { "key" => "value" } } }
71
76
  let(:file_b) { double }
72
77
 
73
- it "responds to nested key values" do
78
+ it "responds to nested symbol key values" do
74
79
  subject.file_a[:nested][:key].should be_eql "value"
75
80
  end
81
+
82
+ it "responds to nested string key values" do
83
+ subject.file_a["nested"]["key"].should be_eql "value"
84
+ end
76
85
  end
77
86
 
78
87
  context "when a file first level keys is environment names" do
79
88
  let(:file_b) { double }
80
89
  let(:file_a) do
81
- { test: { key: "value_test" },
82
- development: { key: "value_dev" } }
90
+ { "test" => { "key" => "value_test" },
91
+ "development" => { "key" => "value_dev" } }
83
92
  end
84
93
 
85
94
  before { ENV["RACK_ENV"] = "test" }
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_yml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vitor Kiyoshi Arimitsu
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-20 00:00:00.000000000 Z
11
+ date: 2014-03-26 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A very simple way of configure your ruby applications through yaml files.
15
14
  email: to@vitork.com
@@ -17,7 +16,8 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
- - .gitignore
19
+ - ".gitignore"
20
+ - ".travis.yml"
21
21
  - Gemfile
22
22
  - Gemfile.lock
23
23
  - README.md
@@ -37,27 +37,26 @@ files:
37
37
  homepage: https://github.com/vitork/config_yml
38
38
  licenses:
39
39
  - MIT
40
+ metadata: {}
40
41
  post_install_message:
41
42
  rdoc_options: []
42
43
  require_paths:
43
44
  - lib
44
45
  required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
46
  requirements:
47
- - - ! '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
- none: false
52
51
  requirements:
53
- - - ! '>='
52
+ - - ">="
54
53
  - !ruby/object:Gem::Version
55
54
  version: '0'
56
55
  requirements: []
57
56
  rubyforge_project:
58
- rubygems_version: 1.8.25
57
+ rubygems_version: 2.2.0
59
58
  signing_key:
60
- specification_version: 3
59
+ specification_version: 4
61
60
  summary: Simplify your app configuration.
62
61
  test_files:
63
62
  - spec/lib/configuration/syntax/conf_spec.rb