shenvy 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/shenvy/version.rb +3 -0
- data/lib/shenvy.rb +44 -0
- data/shenvy.gemspec +33 -0
- data/spec/example_env +9 -0
- data/spec/shenv_spec.rb +45 -0
- data/spec/spec_helper.rb +2 -0
- metadata +205 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81e3d011319c6357a48e743e7f6d319ac45cf4fd
|
4
|
+
data.tar.gz: 046d6bbc596d264aec51d73afcb5d158efbf061f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa25883f7f9b41a088e51e5f1689c5a0e6feba15fb3394cb2d4fdc602a57ce03b0efb65c88b70ee642ae5ce841dee4ebb4dc36a4179067abbb46816c03db5d4e
|
7
|
+
data.tar.gz: b5749a691d960153fbb33f7bac6f621dc254f7aab6e21fbfe90311bfc00431b9c99c073b285d5f2d6c1f5398b273d5ac41b7a873f245d157bb126942bd96da5d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 bmd
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
[](https://travis-ci.org/brianmd/shenvy) [](http://badge.fury.io/rb/shenvy) [](https://coveralls.io/r/brianmd/shenvy)
|
2
|
+
|
3
|
+
# Shenvy
|
4
|
+
|
5
|
+
This gem loads the environment created by a shelscript into Ruby's ENV hash.
|
6
|
+
|
7
|
+
The genesis of this is the need to load .envrc files (used by direnv) into RubyMine.
|
8
|
+
It has the same concept as the dotenv and figaro gems, but for arbitrarily complex shell scripts.
|
9
|
+
|
10
|
+
An example of where I use this is opting different services when at work vs away from work.
|
11
|
+
|
12
|
+
```sh
|
13
|
+
# local, dev, or prod
|
14
|
+
DATABASE=local
|
15
|
+
REDIS=dev
|
16
|
+
# ...
|
17
|
+
|
18
|
+
|
19
|
+
if [ $DATABASE == "dev" ]; then
|
20
|
+
export BLUE_HARVEST_HOST=mysql.dev
|
21
|
+
export BLUE_HARVEST_DATABASE=blue_harvest_dev
|
22
|
+
elif [ $DATABASE == "local" ]; then
|
23
|
+
export BLUE_HARVEST_HOST=localhost
|
24
|
+
export BLUE_HARVEST_DATABASE=blue_harvest_dev
|
25
|
+
elif [ $DATABASE == "prod" ]; then
|
26
|
+
export BLUE_HARVEST_HOST=mysql.prod
|
27
|
+
export BLUE_HARVEST_DATABASE=blue_harvest_production
|
28
|
+
else
|
29
|
+
echo
|
30
|
+
echo "ERROR: DATABASE was not set."
|
31
|
+
echo
|
32
|
+
exit 1
|
33
|
+
fi
|
34
|
+
|
35
|
+
if [ $REDIS == "dev" ]; then
|
36
|
+
# ...
|
37
|
+
fi
|
38
|
+
```
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
Add this line to your application's Gemfile:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'shenvy'
|
46
|
+
```
|
47
|
+
|
48
|
+
And then execute:
|
49
|
+
|
50
|
+
$ bundle
|
51
|
+
|
52
|
+
Or install it yourself as:
|
53
|
+
|
54
|
+
$ gem install shenvy
|
55
|
+
|
56
|
+
## Usage
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'shenvy'
|
60
|
+
Shenv.load(filename_to_load)
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
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).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shenvy.
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "shenvy"
|
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/setup
ADDED
data/lib/shenvy.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'shenvy/version'
|
3
|
+
|
4
|
+
module Shenvy
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def load(filename='.env')
|
8
|
+
sourced_env = env(filename)
|
9
|
+
sourced_env.each do |key,val|
|
10
|
+
ENV[key] = val
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def env(filename='.env')
|
15
|
+
path = Pathname.new(filename).expand_path
|
16
|
+
raise "File #{path} not found" unless path.exist?
|
17
|
+
str = `source '#{path}' && set`
|
18
|
+
env_as_hash(str)
|
19
|
+
end
|
20
|
+
|
21
|
+
def env_as_hash(str=get_env)
|
22
|
+
hash = {}
|
23
|
+
env_as_array(str).each{ |key,val| hash[key] = val }
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def env_as_array(str=get_env)
|
28
|
+
env_rows = str.split("\n")
|
29
|
+
pairs = env_rows.collect{ |row| row.split('=', 2) }
|
30
|
+
pairs = pairs.select{ |key,val| !key.nil? and !val.nil? }
|
31
|
+
pairs.collect do |key,val|
|
32
|
+
val = if val.size>1 and val[0]=="'" and val[-1]=="'"
|
33
|
+
val[1..-2]
|
34
|
+
else
|
35
|
+
val
|
36
|
+
end
|
37
|
+
[key,val]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_env
|
42
|
+
`set`
|
43
|
+
end
|
44
|
+
end
|
data/shenvy.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 'shenvy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shenvy"
|
8
|
+
spec.version = Shenvy::VERSION
|
9
|
+
spec.authors = ["Brian Murphy-Dye"]
|
10
|
+
spec.email = ["brian@murphydye.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Loads the environment created by a shell script into Ruby's ENV hash}
|
13
|
+
spec.description = %q{Useful for loading complex shell script environments (such as those composed when using
|
14
|
+
direnv) into RubyMine.}
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec-nc"
|
27
|
+
spec.add_development_dependency "guard"
|
28
|
+
spec.add_development_dependency "guard-rspec"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "pry-remote"
|
31
|
+
spec.add_development_dependency "pry-nav"
|
32
|
+
spec.add_development_dependency "coveralls"
|
33
|
+
end
|
data/spec/example_env
ADDED
data/spec/shenv_spec.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shenvy do
|
4
|
+
let(:example_env) { Pathname(__FILE__).dirname + 'example_env' }
|
5
|
+
|
6
|
+
it 'loads existing environment into a hash' do
|
7
|
+
shenvy_key = 'this is a shenvy test'
|
8
|
+
shenvy_val = '7'
|
9
|
+
ENV[shenvy_key] = shenvy_val
|
10
|
+
array = Shenvy
|
11
|
+
env = Shenvy.env_as_hash
|
12
|
+
expect(env[shenvy_key]).to eq(shenvy_val)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'loads existing environment with an equals sign in the value' do
|
16
|
+
shenvy_key = 'this is a shenvy test 2'
|
17
|
+
shenvy_val = '7 = 6 + 1'
|
18
|
+
ENV[shenvy_key] = shenvy_val
|
19
|
+
env = Shenvy.env_as_hash
|
20
|
+
expect(env[shenvy_key]).to eq(shenvy_val)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'gets environment after sourcing a specific file' do
|
24
|
+
env = Shenvy.env(example_env)
|
25
|
+
expect(env['a']).to eq('a1')
|
26
|
+
expect(env['b']).to eq('b1')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "loads sourced environment into this ruby's ENV" do
|
30
|
+
ENV['a'] = '0'
|
31
|
+
ENV['b'] = '0'
|
32
|
+
expect(ENV['a']).to eq('0')
|
33
|
+
expect(ENV['b']).to eq('0')
|
34
|
+
|
35
|
+
Shenvy.load(example_env)
|
36
|
+
expect(ENV['a']).to eq('a1')
|
37
|
+
expect(ENV['b']).to eq('b1')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'handles a missing environment file' do
|
41
|
+
expect{ Shenvy.load('not-a-file') }.to raise_error(RuntimeError, /not found/)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'ensure environment file is executable.'
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shenvy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Murphy-Dye
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-31 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: rspec
|
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: rspec-nc
|
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: guard
|
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: guard-rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-remote
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-nav
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: |-
|
154
|
+
Useful for loading complex shell script environments (such as those composed when using
|
155
|
+
direnv) into RubyMine.
|
156
|
+
email:
|
157
|
+
- brian@murphydye.com
|
158
|
+
executables:
|
159
|
+
- console
|
160
|
+
- setup
|
161
|
+
extensions: []
|
162
|
+
extra_rdoc_files: []
|
163
|
+
files:
|
164
|
+
- ".gitignore"
|
165
|
+
- ".travis.yml"
|
166
|
+
- Gemfile
|
167
|
+
- LICENSE.txt
|
168
|
+
- README.md
|
169
|
+
- Rakefile
|
170
|
+
- bin/console
|
171
|
+
- bin/setup
|
172
|
+
- lib/shenvy.rb
|
173
|
+
- lib/shenvy/version.rb
|
174
|
+
- shenvy.gemspec
|
175
|
+
- spec/example_env
|
176
|
+
- spec/shenv_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
homepage: ''
|
179
|
+
licenses:
|
180
|
+
- MIT
|
181
|
+
metadata: {}
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
require_paths:
|
185
|
+
- lib
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
requirements: []
|
197
|
+
rubyforge_project:
|
198
|
+
rubygems_version: 2.2.2
|
199
|
+
signing_key:
|
200
|
+
specification_version: 4
|
201
|
+
summary: Loads the environment created by a shell script into Ruby's ENV hash
|
202
|
+
test_files:
|
203
|
+
- spec/example_env
|
204
|
+
- spec/shenv_spec.rb
|
205
|
+
- spec/spec_helper.rb
|