config_env 0.1.1 → 0.1.2
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 +4 -4
- data/.rspec +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +19 -18
- data/config_env.gemspec +2 -2
- data/lib/config_env.rb +27 -37
- data/lib/config_env/version.rb +1 -1
- data/spec/lib/config_env/rake_tasts_spec.rb +0 -1
- data/spec/lib/config_env_spec.rb +4 -5
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e75f4552472ed2977f425b21e00297d7b9dd4621
|
4
|
+
data.tar.gz: 35f68b775b1f64644f2e1902790b55b7136dabe7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f06eafb4efacdeff26ebc735635f97ebf59d6f87805896e0a4f2946f6d5f83983971a57b9b9322f330a6aedca6b48bc6cc0ff505148599eb4043e3c62f005607
|
7
|
+
data.tar.gz: cafdfc567e0cc545c775b6e274b4fda4bc8fcd52777c439f70054ed9d78c736ed761abd784b3656c5da34c8cb4ef0268b04dd4d06a36e0d6f6fa4e745b54b8eb
|
data/.rspec
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
#
|
1
|
+
# Configurate ENV with Ruby syntax. Upload to Heroku
|
2
2
|
|
3
3
|
|
4
4
|
[](https://codeclimate.com/github/SergXIIIth/config_env)
|
5
5
|
[](https://gemnasium.com/SergXIIIth/config_env)
|
6
6
|
|
7
7
|
|
8
|
-
|
8
|
+
Features:
|
9
9
|
|
10
|
-
- Describe `ENV['key']`
|
11
|
-
- Upload
|
10
|
+
- Describe `ENV['key']` configuration with Ruby syntax
|
11
|
+
- Upload configuration to Heroku
|
12
12
|
|
13
13
|
|
14
14
|
## Usage
|
15
15
|
|
16
16
|
```ruby
|
17
17
|
gem 'config_env'
|
18
|
-
|
19
|
-
# Specify path your `config_env.rb`
|
20
|
-
ConfigEnv.path_to_config("#{__dir__}/config/config_env.rb")
|
18
|
+
ConfigEnv.init("#{__dir__}/env.rb")
|
21
19
|
```
|
22
20
|
|
23
21
|
Create file `config/env.rb`:
|
24
22
|
|
25
23
|
```ruby
|
26
24
|
config_env do
|
27
|
-
set '
|
25
|
+
set 'all_env_key', '1'
|
28
26
|
end
|
29
27
|
|
30
28
|
config_env :test do
|
31
|
-
set '
|
29
|
+
set 'test_key', '2'
|
32
30
|
end
|
33
31
|
|
34
32
|
config_env :production, :development do
|
35
|
-
set '
|
33
|
+
set 'production_and_development_key', '3'
|
36
34
|
end
|
37
35
|
```
|
38
36
|
|
39
|
-
|
37
|
+
Add to `application.rb`
|
40
38
|
|
41
|
-
|
39
|
+
```ruby
|
40
|
+
ConfigEnv.init("#{__dir__}/env.rb")
|
41
|
+
```
|
42
42
|
|
43
43
|
Add line to `.gitignore`
|
44
44
|
|
@@ -49,16 +49,17 @@ Add line to `.gitignore`
|
|
49
49
|
|
50
50
|
Add to `Rakefile`
|
51
51
|
|
52
|
+
```ruby
|
52
53
|
require 'config_env/rake_tasks'
|
53
|
-
ConfigEnv.
|
54
|
+
ConfigEnv.init("#{__dir__}/config/env.rb")
|
55
|
+
```
|
54
56
|
|
55
|
-
Run
|
57
|
+
Run
|
56
58
|
|
59
|
+
```bash
|
57
60
|
rake config_env:heroku
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
rake config_env:heroku[app-name]
|
61
|
+
rake config_env:heroku[app]
|
62
|
+
```
|
62
63
|
|
63
64
|
## Contributing
|
64
65
|
|
data/config_env.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ConfigEnv::VERSION
|
9
9
|
spec.authors = ['Sergey Makridenkov']
|
10
10
|
spec.email = ['sergey@makridenkov.com']
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{ENV
|
11
|
+
spec.description = %q{Configurate ENV with Ruby syntax. Upload to Heroku}
|
12
|
+
spec.summary = %q{Configurate ENV variables depend on RACK_ENV. Configuration syntax is Ruby. Upload to Heroku supported}
|
13
13
|
spec.homepage = 'https://github.com/SergXIIIth/config_env'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
data/lib/config_env.rb
CHANGED
@@ -1,31 +1,22 @@
|
|
1
1
|
require "config_env/version"
|
2
2
|
|
3
3
|
module ConfigEnv
|
4
|
-
#
|
4
|
+
# DEPRECATED. Use `init`
|
5
5
|
def self.path_to_config(new_path)
|
6
|
-
|
7
|
-
if File.exists?(path)
|
8
|
-
Kernel.load(path)
|
9
|
-
end
|
6
|
+
init(new_path)
|
10
7
|
end
|
11
8
|
|
12
|
-
def self.
|
13
|
-
@path
|
9
|
+
def self.init(path_to_config)
|
10
|
+
@path = path_to_config
|
11
|
+
Kernel.load(path) if File.exists?(path)
|
14
12
|
end
|
15
13
|
|
16
|
-
def self.
|
17
|
-
@
|
18
|
-
|
19
|
-
envs.each do |env|
|
20
|
-
env = env.to_s
|
21
|
-
@vars[env] ||= {}
|
22
|
-
@vars[env].merge!(vars)
|
23
|
-
end
|
14
|
+
def self.path
|
15
|
+
@path
|
24
16
|
end
|
25
17
|
|
26
18
|
def self.vars(environment = nil)
|
27
|
-
environment
|
28
|
-
environment = environment.to_s
|
19
|
+
environment = (environment || self.environment).to_s
|
29
20
|
|
30
21
|
vars = (vars_hash[environment] || {}).clone
|
31
22
|
vars.merge!(vars_hash["any"] || {})
|
@@ -38,34 +29,36 @@ module ConfigEnv
|
|
38
29
|
end
|
39
30
|
|
40
31
|
def self.environment
|
41
|
-
ENV['RACK_ENV'] || 'development'
|
32
|
+
ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
42
33
|
end
|
43
34
|
|
44
35
|
private
|
45
36
|
|
46
|
-
|
37
|
+
def self.set_envs(vars, envs)
|
38
|
+
envs = envs.map(&:to_s)
|
47
39
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def self.setup_env(vars, envs)
|
53
|
-
if envs == ['any']
|
54
|
-
env_fit = true
|
55
|
-
else
|
56
|
-
env_fit = envs.map{|env| env.to_s}.include?(environment)
|
40
|
+
envs.each do |env|
|
41
|
+
vars_hash[env] ||= {}
|
42
|
+
vars_hash[env].merge!(vars)
|
57
43
|
end
|
58
44
|
|
59
|
-
if
|
45
|
+
if envs == ['any'] || envs.include?(environment)
|
60
46
|
vars.each do |key, value|
|
61
47
|
ENV[key] = value
|
62
48
|
end
|
63
49
|
end
|
64
50
|
end
|
65
51
|
|
66
|
-
|
52
|
+
def self.vars_hash
|
53
|
+
@vars ||= {}
|
54
|
+
end
|
55
|
+
|
56
|
+
class EnvWrap
|
57
|
+
def initialize
|
58
|
+
@vars = {}
|
59
|
+
end
|
60
|
+
|
67
61
|
def set(key, value)
|
68
|
-
@vars ||= {}
|
69
62
|
@vars[key] = value.to_s
|
70
63
|
end
|
71
64
|
|
@@ -74,13 +67,10 @@ private
|
|
74
67
|
end
|
75
68
|
|
76
69
|
def config_env(*envs, &code)
|
77
|
-
|
78
|
-
|
70
|
+
env_wrap = ConfigEnv::EnvWrap.new
|
71
|
+
env_wrap.instance_eval(&code)
|
79
72
|
|
80
73
|
envs = envs.size > 0 ? envs : ['any']
|
81
74
|
|
82
|
-
|
83
|
-
ConfigEnv.set_vars(command.vars, envs)
|
84
|
-
ConfigEnv.setup_env(command.vars, envs)
|
85
|
-
end
|
75
|
+
ConfigEnv.set_envs(env_wrap.vars, envs)
|
86
76
|
end
|
data/lib/config_env/version.rb
CHANGED
data/spec/lib/config_env_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'ostruct'
|
3
2
|
|
4
3
|
describe ConfigEnv do
|
@@ -7,15 +6,15 @@ describe ConfigEnv do
|
|
7
6
|
|
8
7
|
before { ConfigEnv.clear }
|
9
8
|
|
10
|
-
describe '.
|
9
|
+
describe '.init' do
|
11
10
|
let(:path){ double('path') }
|
12
|
-
subject(:
|
11
|
+
subject(:init) { ConfigEnv.init(path) }
|
13
12
|
|
14
13
|
# on Heroku ENV set manually and config_env does not exist
|
15
14
|
context 'when config_env not exist' do
|
16
15
|
it 'do nothing' do
|
17
16
|
expect(Kernel).to_not receive(:load)
|
18
|
-
|
17
|
+
init
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
@@ -26,7 +25,7 @@ describe ConfigEnv do
|
|
26
25
|
|
27
26
|
it 'load config_env' do
|
28
27
|
expect(Kernel).to receive(:load).with(path)
|
29
|
-
|
28
|
+
init
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Makridenkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.10'
|
69
|
-
description:
|
69
|
+
description: Configurate ENV with Ruby syntax. Upload to Heroku
|
70
70
|
email:
|
71
71
|
- sergey@makridenkov.com
|
72
72
|
executables: []
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".rspec"
|
77
78
|
- Gemfile
|
78
79
|
- LICENSE.txt
|
79
80
|
- README.md
|
@@ -108,7 +109,8 @@ rubyforge_project:
|
|
108
109
|
rubygems_version: 2.5.1
|
109
110
|
signing_key:
|
110
111
|
specification_version: 4
|
111
|
-
summary: ENV
|
112
|
+
summary: Configurate ENV variables depend on RACK_ENV. Configuration syntax is Ruby.
|
113
|
+
Upload to Heroku supported
|
112
114
|
test_files:
|
113
115
|
- spec/lib/config_env/rake_tasts_spec.rb
|
114
116
|
- spec/lib/config_env_spec.rb
|