settings-env-loader 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,77 +1,73 @@
1
1
  require "enumerator"
2
2
 
3
- module Settings
4
- module Env
5
- module Loader
6
- VERSION = "0.0.1"
3
+ module SettingsEnvLoader
4
+ VERSION = "0.1.0"
7
5
 
8
- # Merges ENV and modify the hash directly
9
- def merge_env(prefix = nil, separator = '_')
10
- Merger.new(prefix, separator, self).merge
11
- self
12
- end
6
+ # Merges ENV and modify the hash directly
7
+ def merge_env(prefix = nil, separator = '_')
8
+ Merger.new(prefix, separator, self).merge
9
+ self
10
+ end
13
11
 
14
- # Iterates the Hash as ENV key value pairs
15
- def each_env(prefix = nil, separator = '_')
16
- Enumerator.new do |y|
17
- Exporter.new(prefix, separator, self).each(y)
18
- end
19
- end
12
+ # Iterates the Hash as ENV key value pairs
13
+ def each_env(prefix = nil, separator = '_')
14
+ Enumerator.new do |y|
15
+ Exporter.new(prefix, separator, self).each(y)
16
+ end
17
+ end
20
18
 
21
- class Merger
22
- def initialize(prefix, separator, hash)
23
- @prefix = prefix
24
- @separator = separator
25
- @hash = hash
26
- end
19
+ class Merger
20
+ def initialize(prefix, separator, hash)
21
+ @prefix = prefix
22
+ @separator = separator
23
+ @hash = hash
24
+ end
27
25
 
28
- def merge
29
- @hash.each do |key, value|
30
- env_name = [@prefix, key].compact.join(@separator).upcase
26
+ def merge
27
+ @hash.each do |key, value|
28
+ env_name = [@prefix, key].compact.join(@separator).upcase
31
29
 
32
- if value.is_a?(Hash)
33
- Merger.new(env_name, @separator, value).merge
34
- else
35
- env_value = ENV[env_name]
36
- if env_value
37
- @hash[key] = convert(env_value, value)
38
- end
39
- end
30
+ if value.is_a?(Hash)
31
+ Merger.new(env_name, @separator, value).merge
32
+ else
33
+ env_value = ENV[env_name]
34
+ if env_value
35
+ @hash[key] = convert(env_value, value)
40
36
  end
41
37
  end
38
+ end
39
+ end
42
40
 
43
- def convert(value, origin_value)
44
- case origin_value
45
- when Symbol
46
- value.to_sym
47
- when Fixnum
48
- value.to_i
49
- when Float
50
- value.to_f
51
- when Array
52
- Array(YAML.load(value))
53
- else
54
- value
55
- end
56
- end
41
+ def convert(value, origin_value)
42
+ case origin_value
43
+ when Symbol
44
+ value.to_sym
45
+ when Fixnum
46
+ value.to_i
47
+ when Float
48
+ value.to_f
49
+ when Array
50
+ Array(YAML.load(value))
51
+ else
52
+ value
57
53
  end
54
+ end
55
+ end
58
56
 
59
- class Exporter
60
- def initialize(prefix, separator, hash)
61
- @prefix = prefix
62
- @separator = separator
63
- @hash = hash
64
- end
57
+ class Exporter
58
+ def initialize(prefix, separator, hash)
59
+ @prefix = prefix
60
+ @separator = separator
61
+ @hash = hash
62
+ end
65
63
 
66
- def each(y)
67
- @hash.each do |key, value|
68
- env_name = [@prefix, key].compact.join(@separator).upcase
69
- if value.is_a?(Hash)
70
- Exporter.new(env_name, @separator, value).each(y)
71
- else
72
- y << [env_name, value.to_s]
73
- end
74
- end
64
+ def each(y)
65
+ @hash.each do |key, value|
66
+ env_name = [@prefix, key].compact.join(@separator).upcase
67
+ if value.is_a?(Hash)
68
+ Exporter.new(env_name, @separator, value).each(y)
69
+ else
70
+ y << [env_name, value.to_s]
75
71
  end
76
72
  end
77
73
  end
@@ -5,7 +5,7 @@ require 'settings-env-loader'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "settings-env-loader"
8
- gem.version = Settings::Env::Loader::VERSION
8
+ gem.version = SettingsEnvLoader::VERSION
9
9
  gem.authors = ["Ian Yang"]
10
10
  gem.email = ["me@iany.me"]
11
11
  gem.description = %q{Scan ENV and override correspondong settings in a nested Hash}
@@ -1,6 +1,6 @@
1
1
  require 'settings-env-loader'
2
2
 
3
- describe Settings::Env::Loader do
3
+ describe SettingsEnvLoader do
4
4
  let(:hash) do
5
5
  {
6
6
  :float => 1.2,
@@ -16,7 +16,7 @@ describe Settings::Env::Loader do
16
16
  subject { hash }
17
17
 
18
18
  before do
19
- hash.extend Settings::Env::Loader
19
+ hash.extend SettingsEnvLoader
20
20
  end
21
21
 
22
22
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settings-env-loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  segments:
77
77
  - 0
78
- hash: -1968224689981837943
78
+ hash: -4257699166367919171
79
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  none: false
81
81
  requirements:
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  segments:
86
86
  - 0
87
- hash: -1968224689981837943
87
+ hash: -4257699166367919171
88
88
  requirements: []
89
89
  rubyforge_project:
90
90
  rubygems_version: 1.8.23