config_env 0.1.1 → 0.1.2

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: ef1573f36c0335e6447a11bc7727ab2476b79084
4
- data.tar.gz: 4333a92141a27773f65a8b220d62dbcabc590f67
3
+ metadata.gz: e75f4552472ed2977f425b21e00297d7b9dd4621
4
+ data.tar.gz: 35f68b775b1f64644f2e1902790b55b7136dabe7
5
5
  SHA512:
6
- metadata.gz: a8ccb2f23be8ba979276f1efc4406c3188a98b843dd977ce477ced0b9d7c5458f6012925bf146af705f4c1b4a43044a79657af90ed51fa3748359e70a176358a
7
- data.tar.gz: 130661404a0c633644cbbadc07e914e5590e4925399e9843a625e7c429e792da918b8fb03cde5bc9a9171f6de9d872fc76ba405b58da4366ad3ef8e721ae99a5
6
+ metadata.gz: f06eafb4efacdeff26ebc735635f97ebf59d6f87805896e0a4f2946f6d5f83983971a57b9b9322f330a6aedca6b48bc6cc0ff505148599eb4043e3c62f005607
7
+ data.tar.gz: cafdfc567e0cc545c775b6e274b4fda4bc8fcd52777c439f70054ed9d78c736ed761abd784b3656c5da34c8cb4ef0268b04dd4d06a36e0d6f6fa4e745b54b8eb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Sergey Makridenkov
1
+ Copyright (c) 2016 Sergey Makridenkov
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,44 +1,44 @@
1
- # ConfigEnv - config your ENV['variables']
1
+ # Configurate ENV with Ruby syntax. Upload to Heroku
2
2
 
3
3
 
4
4
  [![Code Climate](https://codeclimate.com/github/SergXIIIth/config_env.png)](https://codeclimate.com/github/SergXIIIth/config_env)
5
5
  [![Dependency Status](https://gemnasium.com/SergXIIIth/config_env.svg)](https://gemnasium.com/SergXIIIth/config_env)
6
6
 
7
7
 
8
- Configurator of the `ENV['key']` for any Ruby environment
8
+ Features:
9
9
 
10
- - Describe `ENV['key']` variables in config file with Ruby syntax
11
- - Upload the configuration to Heroku
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 'secret_key', 'value_for_all_RACK_ENV'
25
+ set 'all_env_key', '1'
28
26
  end
29
27
 
30
28
  config_env :test do
31
- set 'secret_key', 'overwrite_value_for_test_rack_env'
29
+ set 'test_key', '2'
32
30
  end
33
31
 
34
32
  config_env :production, :development do
35
- set 'secret_key', 'overwrite_value_for_test_or_dev_rack_env'
33
+ set 'production_and_development_key', '3'
36
34
  end
37
35
  ```
38
36
 
39
- For Rails add to `application.rb`
37
+ Add to `application.rb`
40
38
 
41
- ConfigEnv.path_to_config("#{__dir__}/env.rb")
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.path_to_config("#{__dir__}/config/config_env.rb")
54
+ ConfigEnv.init("#{__dir__}/config/env.rb")
55
+ ```
54
56
 
55
- Run rake command
57
+ Run
56
58
 
59
+ ```bash
57
60
  rake config_env:heroku
58
-
59
- Optionally, you can pass in the name of the Heroku app
60
-
61
- rake config_env:heroku[app-name]
61
+ rake config_env:heroku[app]
62
+ ```
62
63
 
63
64
  ## Contributing
64
65
 
@@ -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{Manage ENV[] variables, upload ENV to Heroku}
12
- spec.summary = %q{ENV manager for any Ruby code}
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
 
@@ -1,31 +1,22 @@
1
1
  require "config_env/version"
2
2
 
3
3
  module ConfigEnv
4
- # path to config_env file. Used in app Rakefile
4
+ # DEPRECATED. Use `init`
5
5
  def self.path_to_config(new_path)
6
- @path = new_path
7
- if File.exists?(path)
8
- Kernel.load(path)
9
- end
6
+ init(new_path)
10
7
  end
11
8
 
12
- def self.path
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.set_vars(vars, envs)
17
- @vars ||= {}
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 ||= self.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
- attr_accessor :vars
37
+ def self.set_envs(vars, envs)
38
+ envs = envs.map(&:to_s)
47
39
 
48
- def self.vars_hash
49
- @vars ||= {}
50
- end
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 env_fit
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
- class Command
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
- command = ConfigEnv::Command.new
78
- command.instance_eval(&code)
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
- if command.vars
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
@@ -1,3 +1,3 @@
1
1
  module ConfigEnv
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'config_env/rake_tasks'
3
2
 
4
3
  module ConfigEnv::Tasks
@@ -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 '.path_to_config' do
9
+ describe '.init' do
11
10
  let(:path){ double('path') }
12
- subject(:path_to_config) { ConfigEnv.path_to_config(path) }
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
- path_to_config
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
- path_to_config
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.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-12 00:00:00.000000000 Z
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: Manage ENV[] variables, upload ENV to Heroku
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 manager for any Ruby code
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