env_json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f71892e15b9324cb66d55ea86434991f106fead8
4
+ data.tar.gz: 5df3330938c9cd28a08d17ec6db9380724a3614e
5
+ SHA512:
6
+ metadata.gz: 3d70122ad83f86d6f249fa867d8593c23a64ad535a02d5f4dfa94de5d8c03868ee7bd636f64ea25a406823d9f64d08242547c777343b3a1ce08bfd40c8a35a1e
7
+ data.tar.gz: 1f393b4fd35635673165b49204a7b44fa7f6f956b9f0fab6418f0c39b178f82fd68109f7c3bc911260d00bc46e0e1d25c5ea7dabdecd5b1e0bcbef722e3c07c2
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in env_json.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # EnvJson
2
+
3
+ [![Build Status](https://travis-ci.org/hellvinz/env_json.png)](https://travis-ci.org/hellvinz/env_json)
4
+
5
+ Load ENV variables from a JSON file. (somehow similar to [dotenv](https://github.com/bkeepers/dotenv))
6
+
7
+ Intended to be used with [ejson](https://github.com/Shopify/ejson)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'env_json'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install env_json
24
+
25
+ ## Usage
26
+
27
+ If you're using Rails create a config/env.json like this template
28
+
29
+ ```json
30
+ {
31
+ "DATABASE_URL": "mysql://@localhost/development_db",
32
+ "test" : {
33
+ "DATABASE_URL": "mysql://login:password@mysql.com/test_db"
34
+ }
35
+ }
36
+ ```
37
+
38
+ But really have a look at [ejson](https://github.com/Shopify/ejson) and [ejson-capistrano](https://github.com/Shopify/capistrano-ejson)
39
+
40
+ About the JSON format:
41
+
42
+ * keys prefixed with _ will be ignored
43
+ * keys development, test, staging, production will be ignored if they don't match with current environment
44
+
45
+ ## Development
46
+
47
+ 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.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hellvinz/env_json. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "yard"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList['spec/**/*_spec.rb']
9
+ end
10
+
11
+ YARD::Rake::YardocTask.new do |t|
12
+ t.files = ['lib/**/*.rb']
13
+ end
14
+
15
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "env_json"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/env_json.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'env_json/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "env_json"
8
+ spec.version = EnvJson::VERSION
9
+ spec.authors = ["Vincent Hellot"]
10
+ spec.email = ["hellvinz@gmail.com"]
11
+
12
+ spec.summary = %q{Load ENV variables from a JSON file}
13
+ spec.description = %q{Load ENV variables from a JSON file. Usefull with ejson https://github.com/Shopify/ejson}
14
+ spec.homepage = "http://github.com/hellvinz/env_json"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
20
+ end
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = "bin"
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency "simplecov"
31
+ spec.add_development_dependency "simplecov-rcov"
32
+ spec.add_development_dependency "yard"
33
+ end
@@ -0,0 +1,11 @@
1
+ module EnvJson
2
+ # Rails hook to autoload ENV from JSON file before configuration
3
+ class Railtie < Rails::Railtie
4
+ config.before_configuration { load_env }
5
+
6
+ # railtie hook to load env with Rails.env as environment name and config/env.json files as source
7
+ def load_env
8
+ EnvJson.load_env_from_source_with_overrides(Rails.root.join('config/env.json'))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module EnvJson
2
+ # EnvJson version
3
+ VERSION = "0.1.0"
4
+ end
data/lib/env_json.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "env_json/version"
2
+ require "json"
3
+
4
+ # Module containing utilities for loading a JSON file into environments variables. see {EnvJson#load_env_from_source_with_overrides}
5
+ module EnvJson
6
+ module_function
7
+
8
+ # Load environments variables from a source into ENV
9
+ #
10
+ # @param json [#read] any source that can be read by JSON.load
11
+ # @param environment_name [#to_str, nil] the environment name from where to take overrides
12
+ # @return [Hash] the loaded environment variables
13
+ def load_env_from_source_with_overrides(json, environment_name=nil)
14
+ json = JSON.load(json)
15
+ generate_configuration(json, environment_name).tap do |configuration|
16
+ apply_env(configuration)
17
+ end
18
+ end
19
+
20
+ # @!visibility private
21
+ def generate_configuration(raw_hash, environment_name=nil, configuration={})
22
+ raw_hash.inject(configuration) do |conf, (key,value)|
23
+ next conf if key =~ /^_/
24
+
25
+ if key == environment_name
26
+ conf = generate_configuration(value, environment_name, conf)
27
+ elsif not value.is_a? String and key =~ /^(test|development|staging|production)/
28
+ # skip other environments keys
29
+ next conf
30
+ else
31
+ conf[key] = value
32
+ end
33
+ conf
34
+ end
35
+ end
36
+
37
+ # @!visibility private
38
+ def apply_env(configuration)
39
+ configuration.each do |key,value|
40
+ ENV[key] ||= value
41
+ end
42
+ end
43
+ end
44
+
45
+ require 'env_json/railtie' if defined?(Rails)
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vincent Hellot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-rcov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Load ENV variables from a JSON file. Usefull with ejson https://github.com/Shopify/ejson
98
+ email:
99
+ - hellvinz@gmail.com
100
+ executables:
101
+ - console
102
+ - rake
103
+ - setup
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/rake
115
+ - bin/setup
116
+ - env_json.gemspec
117
+ - lib/env_json.rb
118
+ - lib/env_json/railtie.rb
119
+ - lib/env_json/version.rb
120
+ homepage: http://github.com/hellvinz/env_json
121
+ licenses: []
122
+ metadata:
123
+ allowed_push_host: https://rubygems.org
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Load ENV variables from a JSON file
144
+ test_files: []
145
+ has_rdoc: