really-confy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/really_confy.rb +29 -24
  3. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4a5653e5cc890738cf6afce11f7da262f814e78
4
- data.tar.gz: 38f63ff32abbff0de095ebe6335d909ad8d935a1
3
+ metadata.gz: c302d38b29348f70a6e2246add5eb28fb4d25b58
4
+ data.tar.gz: b7cf55ba7d1bc753a253a38c5d952405189d8c72
5
5
  SHA512:
6
- metadata.gz: 5af1c19f0ca561a5fe9dcd52fe019ad5e2bc5a20611934156f60ccc3b078daf3e8f5af37cc451b85b9d11c5d93e762f1d899c9f1ce012e78b736ee72856baa50
7
- data.tar.gz: 99c36e189f874ede4a7226943a7fcd1530cc3235d3b08ac1234b8a81644fdca1af16d4766e7b987c61c7bc31d7b41febad54c3f9cef8560525a77f8a6ba5160c
6
+ metadata.gz: 26538073af0b6b3089785ca7eab1d97d4b3601dd7d32b55d2c5aa1305c2531890d5c9fbddea68ae64f42d6733962932cf256c076f03513849390ac8007d9ff02
7
+ data.tar.gz: fad912633f37944bca950a92800c5b66f0f5386fdd539cf93f6d7583f45b09fcb5d85c2f9a5e7504cfc3b9c7b70a7713287f6ef1feefe32d7ede7b8467165539
data/lib/really_confy.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'yaml'
2
+ require 'hashie/mash'
3
+ require 'hashie/extensions/parsers/yaml_erb_parser'
4
+ require 'hashie/extensions/deep_fetch'
2
5
  require 'rainbow'
3
- require 'active_support/core_ext/hash/deep_merge'
4
6
 
5
7
  class ReallyConfy
6
8
 
@@ -30,10 +32,6 @@ class ReallyConfy
30
32
  ],
31
33
  # the environment key will be selected based on this ENV variable
32
34
  env_var_name: 'CONFY_ENV',
33
- # use Symbols instead of Strings for all keys in the config Hash
34
- symbol_keys: false,
35
- # load will return an ActiveSupport::HashWithIndifferentAccess instead of a Hash
36
- indifferent_keys: false,
37
35
  # suppress output to stdout/stderr
38
36
  quiet: false,
39
37
  # enable colorized output; nil means 'auto', which enables color by default unless the
@@ -41,7 +39,9 @@ class ReallyConfy
41
39
  color: nil,
42
40
  # force the ruby interpreter to exit if ReallyConfy encounters an error during load
43
41
  # ... not a good idea to use this with quiet:true unless you know exactly what you're doing
44
- exit_on_error: false
42
+ exit_on_error: false,
43
+ # Don't allow (inadvertent) modification of the config once it's been loaded
44
+ read_only: false
45
45
  }
46
46
 
47
47
  attr_accessor :config_files
@@ -67,14 +67,6 @@ class ReallyConfy
67
67
  ensure_required_config_files_exist
68
68
  check_suggested_config_files_exist
69
69
  ensure_local_config_files_are_not_in_git
70
-
71
- if @symbol_keys && @indifferent_keys
72
- fail ArgumentError,
73
- ":symbol_keys and :indifferent_keys options cannot be used together!"
74
- end
75
-
76
- require 'active_support/core_ext/hash/keys' if @symbol_keys
77
- require 'active_support/core_ext/hash/indifferent_access' if @indifferent_keys
78
70
  end
79
71
 
80
72
  def load
@@ -87,7 +79,7 @@ class ReallyConfy
87
79
  multi_env_configs =
88
80
  existing_config_files.map{|file| load_config_file(file) }
89
81
 
90
- unless multi_env_configs.any?{|config| config.is_a?(Hash) && config.has_key?(env) }
82
+ unless multi_env_configs.any?{|config| config.has_key?(env) }
91
83
  fail ConfigError, "#{env.inspect} is not a valid environment! None of the loaded configs"+
92
84
  " had a top-level #{env.inspect} key. All configurations should be nested under top"+
93
85
  " level keys corresponding to environment names (e.g. 'test', 'development', ...)"
@@ -100,8 +92,9 @@ class ReallyConfy
100
92
 
101
93
  merged_config['env'] ||= env
102
94
 
103
- merged_config.deep_symbolize_keys! if @symbol_keys
104
- merged_config = merged_config.with_indifferent_access if @indifferent_keys
95
+ if @read_only
96
+ merged_config.freeze
97
+ end
105
98
 
106
99
  merged_config
107
100
  rescue => e
@@ -113,6 +106,9 @@ class ReallyConfy
113
106
  print_error ""
114
107
  print_error "#{e}"
115
108
  print_error ""
109
+ print_error "BACKTRACE:"
110
+ print_error " #{e.backtrace.join("\n ")}"
111
+ print_error ""
116
112
  print_error "!"*header.length
117
113
  print_error ""
118
114
  if @exit_on_error
@@ -124,14 +120,11 @@ class ReallyConfy
124
120
 
125
121
  def load_config_file(file)
126
122
  full_path = full_path_to_config_file(file)
127
- multi_env_config = (YAML.load_file full_path)
128
-
129
- # YAML.load_file will return false if given an empty file to load
130
- return {} if multi_env_config == false
131
123
 
132
- unless multi_env_config.is_a? Hash
133
- fail ConfigError, "Config file #{file.inspect} must contain a YAML-encoded Hash, but"+
134
- " it seems to contain a #{multi_env_config.class}"
124
+ if File.exists? full_path
125
+ multi_env_config = (ReallyConfy::Config.load full_path)
126
+ else
127
+ multi_env_config = ReallyConfy::Config.new {}
135
128
  end
136
129
 
137
130
  multi_env_config
@@ -229,6 +222,18 @@ class ReallyConfy
229
222
  end
230
223
  end
231
224
 
225
+ class Config < Hashie::Mash
226
+ include Hashie::Extensions::DeepFetch
227
+
228
+ def freeze
229
+ super
230
+ self.values.each do |v|
231
+ v.freeze
232
+ end
233
+ self
234
+ end
235
+ end
236
+
232
237
  class ConfigError < StandardError
233
238
  end
234
239
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: really-confy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zukowski
@@ -11,33 +11,33 @@ cert_chain: []
11
11
  date: 2015-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: rainbow
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rainbow
28
+ name: hashie
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '3.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '3.4'
41
41
  description:
42
42
  email: mzukowski@adknowledge.com
43
43
  executables: []