confg 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d45204ad178ecb48bc4519f2218f3b6600b0504
4
- data.tar.gz: 390d675ea28c999b2c87f48614f8eeeb5301d68d
3
+ metadata.gz: 3a22248aee15636933d13104780068971f2663a3
4
+ data.tar.gz: e8b1bbf96b54edf9cf796ed5c49724df47b93f87
5
5
  SHA512:
6
- metadata.gz: a5b0bbf3257262ec56ca32fc75f01a132fea29768b36dc3a2d6ed2c04e608675fbc1e2fd195ee9aff6f633ea3a917fed16f5c126e11ab8ef022e3df6253dbb86
7
- data.tar.gz: 766c9238541c602b8cd5e6c73d1daab7a993f5fccf618c479a4a151e01a1bed0bc0d01c8853b69267a09b0b6a48cdfafa806d4d6d5f45addfcdcae9c6b038066
6
+ metadata.gz: 2e7cf98c81efeb762c04acc64c82e7c15a5792d9b54c8a1de90433562e4fcd27f797fc09869abaa297b9881270d40b9d3dd06017984f43337cc82527129092b8
7
+ data.tar.gz: 12dfb2ab1b2d4c6c1a1e5cff7adf12a0e3ffc8919686e09a72f54cffc9b251f4fcaeb37e27faa7b20e7f81b1d2a5957cc4caf348eb7e876498b3eadf89eddc58
@@ -18,6 +18,15 @@ module Confg
18
18
  end
19
19
  alias_method :merge!, :merge
20
20
 
21
+ def to_hash
22
+ out = @attributes.to_h.dup
23
+ out.each_pair do |k,v|
24
+ out[k] = v.to_hash if v.is_a?(self.class)
25
+ end
26
+ out
27
+ end
28
+ alias_method :to_h, :to_hash
29
+
21
30
  def [](key)
22
31
  self.get(key)
23
32
  end
@@ -36,10 +45,10 @@ module Confg
36
45
 
37
46
  def load_key(key)
38
47
  # loads yaml file with given key
39
- load_yaml(key, key)
48
+ load_yaml(key, key: key)
40
49
  end
41
50
 
42
- def load_yaml(path, key = nil)
51
+ def load_yaml(path, key: nil, ignore_env: false)
43
52
  path = find_config_yaml(path)
44
53
  raw_content = File.open(path, 'r'){|io| io.read } rescue nil
45
54
 
@@ -48,8 +57,10 @@ module Confg
48
57
  ctxt = ::Confg::ErbContext.new
49
58
  content = ctxt.evaluate(raw_content)
50
59
 
51
- env = defined?(Rails) ? Rails.env.to_s : ENV["RAILS_ENV"] || ENV["RACK_ENV"]
52
- content = content[Rails.env] if env && content.is_a?(::Hash) && content.has_key?(Rails.env)
60
+ unless ignore_env
61
+ env = defined?(Rails) ? Rails.env.to_s : ENV["RAILS_ENV"] || ENV["RACK_ENV"]
62
+ content = content[Rails.env] if env && content.is_a?(::Hash) && content.has_key?(Rails.env)
63
+ end
53
64
 
54
65
  if key
55
66
  self.set(key, content)
@@ -1,3 +1,3 @@
1
1
  module Confg
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-01 00:00:00.000000000 Z
11
+ date: 2017-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport