env_json 0.1.0 → 0.2.0

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: f71892e15b9324cb66d55ea86434991f106fead8
4
- data.tar.gz: 5df3330938c9cd28a08d17ec6db9380724a3614e
3
+ metadata.gz: 8f7970bc17f55af5930aee2d99e760e8936ebaf8
4
+ data.tar.gz: 6f3b6cf9497ad46c951f5f16a05606b4a5a2f3e1
5
5
  SHA512:
6
- metadata.gz: 3d70122ad83f86d6f249fa867d8593c23a64ad535a02d5f4dfa94de5d8c03868ee7bd636f64ea25a406823d9f64d08242547c777343b3a1ce08bfd40c8a35a1e
7
- data.tar.gz: 1f393b4fd35635673165b49204a7b44fa7f6f956b9f0fab6418f0c39b178f82fd68109f7c3bc911260d00bc46e0e1d25c5ea7dabdecd5b1e0bcbef722e3c07c2
6
+ metadata.gz: fd83b2885239d351efa282f245cee293bf5bf05141aef30178c034ab65e5b72021c5159060d88bbd38bbdc9513a5afb0a1857c09abf876cf839b1a88e4498303
7
+ data.tar.gz: 3c2ad3c5a415234ba6e79ce7a3f5f54d92082cd98e13f4428e711ee9b4b01d08f2254bf12334cc5c03204e136bd26b4da5395d4c7fac59576bd9c07f7b6b9c37
data/README.md CHANGED
@@ -42,6 +42,14 @@ About the JSON format:
42
42
  * keys prefixed with _ will be ignored
43
43
  * keys development, test, staging, production will be ignored if they don't match with current environment
44
44
 
45
+ ### ElasticBeanstalk
46
+
47
+ export env variables defined in config/env.json to Amazon ElasticBeanstalk environment
48
+
49
+ ```
50
+ bundle exec rake env_json:eb
51
+ ```
52
+
45
53
  ## Development
46
54
 
47
55
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,25 @@
1
+ require 'pty'
2
+ require 'shellwords'
3
+
4
+ namespace :env_json do
5
+ desc 'print env_json computed environment'
6
+ task print_env: :environment do
7
+ pp EnvJson.env
8
+ end
9
+
10
+ desc 'load env into ElasticBeanstalk'
11
+ task eb: :environment do
12
+ eb_formated_env = EnvJson.env.map{|key,value| "#{Shellwords.escape key}=#{Shellwords.escape value}" }.join(' ')
13
+ begin
14
+ PTY.spawn("eb setenv -v #{eb_formated_env}") do |stdin, stdout, pid|
15
+ begin
16
+ stdin.each { |line| print line }
17
+ rescue Errno::EIO
18
+ puts "Errno:EIO error, but this probably just means that the process has finished giving output"
19
+ end
20
+ end
21
+ rescue PTY::ChildExited
22
+ puts "The child process exited!"
23
+ end
24
+ end
25
+ end
@@ -5,7 +5,11 @@ module EnvJson
5
5
 
6
6
  # railtie hook to load env with Rails.env as environment name and config/env.json files as source
7
7
  def load_env
8
- EnvJson.load_env_from_source_with_overrides(Rails.root.join('config/env.json'))
8
+ EnvJson.load_env_from_source_with_overrides(Rails.root.join('config/env.json'), Rails.env)
9
+ end
10
+
11
+ rake_tasks do
12
+ load File.join(__dir__, 'rails_tasks.rb')
9
13
  end
10
14
  end
11
15
  end
@@ -1,4 +1,4 @@
1
1
  module EnvJson
2
2
  # EnvJson version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
data/lib/env_json.rb CHANGED
@@ -12,11 +12,17 @@ module EnvJson
12
12
  # @return [Hash] the loaded environment variables
13
13
  def load_env_from_source_with_overrides(json, environment_name=nil)
14
14
  json = JSON.load(json)
15
- generate_configuration(json, environment_name).tap do |configuration|
15
+ @env = generate_configuration(json, environment_name).tap do |configuration|
16
16
  apply_env(configuration)
17
17
  end
18
18
  end
19
19
 
20
+ # return the consolidated env built by {EnvJson#load_env_from_source_with_overrides}
21
+ # @return [Hash] the environment variables loaded from JSON
22
+ def env
23
+ @env or fail 'call load_env_from_source_with_overrides first'
24
+ end
25
+
20
26
  # @!visibility private
21
27
  def generate_configuration(raw_hash, environment_name=nil, configuration={})
22
28
  raw_hash.inject(configuration) do |conf, (key,value)|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env_json
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
  - Vincent Hellot
@@ -115,6 +115,7 @@ files:
115
115
  - bin/setup
116
116
  - env_json.gemspec
117
117
  - lib/env_json.rb
118
+ - lib/env_json/rails_tasks.rb
118
119
  - lib/env_json/railtie.rb
119
120
  - lib/env_json/version.rb
120
121
  homepage: http://github.com/hellvinz/env_json