config_yml 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5aa06e511ebafbb6657ccf82c486604df2ab9e7
4
- data.tar.gz: 511f5a9adc69069ab065f75bf4324bc42b50284a
3
+ metadata.gz: 50141adecf0852edc755f184600240f10c219f05
4
+ data.tar.gz: 6d2a3cec733919f63b6f44df8bace847dab31197
5
5
  SHA512:
6
- metadata.gz: a1265a4bbeb96eecc819e8ac95c467d66fc41444a029b4fe5591b3434d5a155da4ef7c0c62f7d3436b7eaf36868376754d5911d8ba0a9edfbf421121ed7f6e7b
7
- data.tar.gz: d6c7bf958a61d6c63d82e0cf907754b201dde04b8d43fc835157681cbc96a98a482d87524dca14d9a3c101b7e6a6818c18c55dccd498842f8882f21563d4c9b8
6
+ metadata.gz: 3ed1e0848acccc1dbd458efe227ea3c1fc2062cf26afa877e5261c3cc4d7fd1ccdba1141545829b5b3954023a9507a3cf225cdcb05adaea6908549c506444ec0
7
+ data.tar.gz: a7b6155edb94d7ae02803ad02b949e30e6b1bf50c69270ce3317509a894c45ab8cddeebc401f4fbddd26a6499dfe3ad3d7e5ed13ffb958135756a2cb16dad2e6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- config_yml (0.0.6)
4
+ config_yml (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module Configuration
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
  end
data/lib/configuration.rb CHANGED
@@ -20,14 +20,16 @@ module Configuration
20
20
  # Configuration.database # => { :host => "localhost", :username => "root" }
21
21
  #
22
22
  class << self
23
+ attr_accessor :root
24
+
23
25
  def method_missing(method, *args)
24
- if file = files.select { |f| f == "config/#{method.to_s}.yml" }[0]
26
+ if file = files.select { |f| f == files_path(method.to_s) }[0]
25
27
  hash[method] ||= load_yml(file)
26
28
  end
27
29
  end
28
30
 
29
31
  def files
30
- @files ||= Dir.glob("config/*.yml")
32
+ @files ||= Dir.glob(files_path)
31
33
  end
32
34
 
33
35
  def env
@@ -36,6 +38,10 @@ module Configuration
36
38
 
37
39
  private
38
40
 
41
+ def files_path(filename="*")
42
+ root.nil? ? "config/#{filename}.yml" : File.join(root, "config/#{filename}.yml")
43
+ end
44
+
39
45
  def hash
40
46
  @hash ||= {}
41
47
  end
@@ -103,6 +103,28 @@ describe Configuration do
103
103
  end
104
104
  end
105
105
 
106
+ context "when the configuration root is specified" do
107
+ let(:file_a) do
108
+ { "key" => "value_test" }
109
+ end
110
+ let(:file_b) { double }
111
+ let(:files) { ["foo/bar/config/file_a.yml", "foo/bar/config/file_b.yml"] }
112
+
113
+ before do
114
+ subject.instance_variable_set(:@files, nil)
115
+ Configuration.root = "foo/bar"
116
+ end
117
+ after { Configuration.root = nil }
118
+
119
+ it "has a root set" do
120
+ Configuration.root.should be_eql "foo/bar"
121
+ end
122
+
123
+ it "returns value" do
124
+ subject.file_a[:key].should be_eql "value_test"
125
+ end
126
+ end
127
+
106
128
  context "when configuration file doesn't exist" do
107
129
  let(:file_a) { double }
108
130
  let(:file_b) { double }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_yml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitor Kiyoshi Arimitsu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A very simple way of configure your ruby applications through yaml files.
14
14
  email: to@vitork.com