envlogic 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +202 -0
- data/MIT-LICENCE +18 -0
- data/README.md +105 -0
- data/Rakefile +18 -0
- data/envlogic.gemspec +22 -0
- data/lib/envlogic.rb +38 -0
- data/lib/envlogic/env.rb +46 -0
- data/lib/envlogic/string_refinements.rb +16 -0
- data/lib/envlogic/version.rb +5 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c49436c445e6972158bc5a71d120d391f1fd7d4
|
4
|
+
data.tar.gz: c96464929defa28a9246f8381872ffa6cae68501
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c1fc754d49f07e35507c30bc5e6d5962cbbcbe41787f39b69d036f9f7f20cfa06c62e6984e30389c084dc9576fc65f9dbf7924a80d990042c0bc2e5bee798c3
|
7
|
+
data.tar.gz: a8456e2b787f72a0083047acbc3bb593bda7834f7c91eb43d8692447b53cc14cbc01aef8bf036c31a4dd691362c37bda26e3e78168a76ec185854730cb0dd928
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Created by .ignore support plugin (hsz.mobi)
|
2
|
+
.idea
|
3
|
+
|
4
|
+
### SublimeText template
|
5
|
+
# cache files for sublime text
|
6
|
+
*.tmlanguage.cache
|
7
|
+
*.tmPreferences.cache
|
8
|
+
*.stTheme.cache
|
9
|
+
|
10
|
+
# workspace files are user-specific
|
11
|
+
*.sublime-workspace
|
12
|
+
|
13
|
+
# project files should be checked into the repository, unless a significant
|
14
|
+
# proportion of contributors will probably not be using SublimeText
|
15
|
+
# *.sublime-project
|
16
|
+
|
17
|
+
# sftp configuration file
|
18
|
+
sftp-config.json
|
19
|
+
|
20
|
+
|
21
|
+
### Ruby template
|
22
|
+
*.gem
|
23
|
+
*.rbc
|
24
|
+
/.config
|
25
|
+
/coverage/
|
26
|
+
/InstalledFiles
|
27
|
+
/pkg/
|
28
|
+
/spec/reports/
|
29
|
+
/test/tmp/
|
30
|
+
/test/version_tmp/
|
31
|
+
/tmp/
|
32
|
+
|
33
|
+
## Specific to RubyMotion:
|
34
|
+
.dat*
|
35
|
+
.repl_history
|
36
|
+
build/
|
37
|
+
|
38
|
+
## Documentation cache and generated files:
|
39
|
+
/.yardoc/
|
40
|
+
/_yardoc/
|
41
|
+
/doc/
|
42
|
+
/rdoc/
|
43
|
+
|
44
|
+
## Environment normalisation:
|
45
|
+
/.bundle/
|
46
|
+
/vendor/bundle
|
47
|
+
/app/lib/bundler/man/
|
48
|
+
|
49
|
+
# for a library or gem, you might want to ignore these files since the code is
|
50
|
+
# intended to run in multiple environments; otherwise, check them in:
|
51
|
+
# Gemfile.lock
|
52
|
+
# .ruby-version
|
53
|
+
# .ruby-gemset
|
54
|
+
|
55
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
56
|
+
.rvmrc
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
env_logic
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
envlogic (1.0.0)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract_type (0.0.7)
|
11
|
+
activemodel (4.2.4)
|
12
|
+
activesupport (= 4.2.4)
|
13
|
+
builder (~> 3.1)
|
14
|
+
activesupport (4.2.4)
|
15
|
+
i18n (~> 0.7)
|
16
|
+
json (~> 1.7, >= 1.7.7)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
adamantium (0.2.0)
|
21
|
+
ice_nine (~> 0.11.0)
|
22
|
+
memoizable (~> 0.4.0)
|
23
|
+
ast (2.1.0)
|
24
|
+
astrolabe (1.3.1)
|
25
|
+
parser (~> 2.2)
|
26
|
+
axiom-types (0.1.1)
|
27
|
+
descendants_tracker (~> 0.0.4)
|
28
|
+
ice_nine (~> 0.11.0)
|
29
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
30
|
+
brakeman (3.1.0)
|
31
|
+
erubis (~> 2.6)
|
32
|
+
fastercsv (~> 1.5)
|
33
|
+
haml (>= 3.0, < 5.0)
|
34
|
+
highline (~> 1.6)
|
35
|
+
multi_json (~> 1.2)
|
36
|
+
ruby2ruby (>= 2.1.1, < 2.3.0)
|
37
|
+
ruby_parser (~> 3.7.0)
|
38
|
+
sass (~> 3.0)
|
39
|
+
slim (>= 1.3.6, < 4.0)
|
40
|
+
terminal-table (~> 1.4.5)
|
41
|
+
bson (3.2.3)
|
42
|
+
builder (3.2.2)
|
43
|
+
coderay (1.1.0)
|
44
|
+
coercible (1.0.0)
|
45
|
+
descendants_tracker (~> 0.0.1)
|
46
|
+
concord (0.1.5)
|
47
|
+
adamantium (~> 0.2.0)
|
48
|
+
equalizer (~> 0.0.9)
|
49
|
+
connection_pool (2.2.0)
|
50
|
+
descendants_tracker (0.0.4)
|
51
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
52
|
+
diff-lcs (1.2.5)
|
53
|
+
docile (1.1.5)
|
54
|
+
equalizer (0.0.11)
|
55
|
+
erubis (2.7.0)
|
56
|
+
faker (1.5.0)
|
57
|
+
i18n (~> 0.5)
|
58
|
+
fastercsv (1.5.5)
|
59
|
+
flay (2.4.0)
|
60
|
+
ruby_parser (~> 3.0)
|
61
|
+
sexp_processor (~> 4.0)
|
62
|
+
flog (4.2.1)
|
63
|
+
ruby_parser (~> 3.1, > 3.1.0)
|
64
|
+
sexp_processor (~> 4.4)
|
65
|
+
haml (4.0.7)
|
66
|
+
tilt
|
67
|
+
haml-lint (0.13.0)
|
68
|
+
haml (~> 4.0)
|
69
|
+
rubocop (>= 0.25.0)
|
70
|
+
sysexits (~> 1.1)
|
71
|
+
highline (1.7.3)
|
72
|
+
i18n (0.7.0)
|
73
|
+
ice_nine (0.11.1)
|
74
|
+
json (1.8.3)
|
75
|
+
memoizable (0.4.2)
|
76
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
77
|
+
method_source (0.8.2)
|
78
|
+
minitest (5.8.0)
|
79
|
+
mongoid (4.0.2)
|
80
|
+
activemodel (~> 4.0)
|
81
|
+
moped (~> 2.0.0)
|
82
|
+
origin (~> 2.1)
|
83
|
+
tzinfo (>= 0.3.37)
|
84
|
+
mongoid-rspec (2.2.0)
|
85
|
+
mongoid (~> 4.0.0)
|
86
|
+
rake
|
87
|
+
rspec (~> 3.1)
|
88
|
+
moped (2.0.7)
|
89
|
+
bson (~> 3.0)
|
90
|
+
connection_pool (~> 2.0)
|
91
|
+
optionable (~> 0.2.0)
|
92
|
+
multi_json (1.11.2)
|
93
|
+
optionable (0.2.0)
|
94
|
+
origin (2.1.1)
|
95
|
+
parser (2.2.2.6)
|
96
|
+
ast (>= 1.1, < 3.0)
|
97
|
+
polishgeeks-dev-tools (1.1.2)
|
98
|
+
brakeman
|
99
|
+
faker
|
100
|
+
haml-lint
|
101
|
+
mongoid-rspec
|
102
|
+
pry
|
103
|
+
rspec
|
104
|
+
rubocop
|
105
|
+
rubycritic (= 1.2.1)
|
106
|
+
shoulda
|
107
|
+
simplecov
|
108
|
+
timecop
|
109
|
+
yard
|
110
|
+
powerpack (0.1.1)
|
111
|
+
procto (0.0.2)
|
112
|
+
pry (0.10.1)
|
113
|
+
coderay (~> 1.1.0)
|
114
|
+
method_source (~> 0.8.1)
|
115
|
+
slop (~> 3.4)
|
116
|
+
rainbow (2.0.0)
|
117
|
+
rake (10.4.2)
|
118
|
+
reek (1.6.3)
|
119
|
+
parser (~> 2.2.0.pre.7)
|
120
|
+
rainbow (>= 1.99, < 3.0)
|
121
|
+
unparser (~> 0.2.2)
|
122
|
+
rspec (3.3.0)
|
123
|
+
rspec-core (~> 3.3.0)
|
124
|
+
rspec-expectations (~> 3.3.0)
|
125
|
+
rspec-mocks (~> 3.3.0)
|
126
|
+
rspec-core (3.3.2)
|
127
|
+
rspec-support (~> 3.3.0)
|
128
|
+
rspec-expectations (3.3.1)
|
129
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
130
|
+
rspec-support (~> 3.3.0)
|
131
|
+
rspec-mocks (3.3.2)
|
132
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
133
|
+
rspec-support (~> 3.3.0)
|
134
|
+
rspec-support (3.3.0)
|
135
|
+
rubocop (0.33.0)
|
136
|
+
astrolabe (~> 1.3)
|
137
|
+
parser (>= 2.2.2.5, < 3.0)
|
138
|
+
powerpack (~> 0.1)
|
139
|
+
rainbow (>= 1.99.1, < 3.0)
|
140
|
+
ruby-progressbar (~> 1.4)
|
141
|
+
ruby-progressbar (1.7.5)
|
142
|
+
ruby2ruby (2.2.0)
|
143
|
+
ruby_parser (~> 3.1)
|
144
|
+
sexp_processor (~> 4.0)
|
145
|
+
ruby_parser (3.7.1)
|
146
|
+
sexp_processor (~> 4.1)
|
147
|
+
rubycritic (1.2.1)
|
148
|
+
flay (= 2.4.0)
|
149
|
+
flog (= 4.2.1)
|
150
|
+
parser (>= 2.2.0, < 3.0)
|
151
|
+
reek (= 1.6.3)
|
152
|
+
ruby2ruby (>= 2.1.1, < 3.0)
|
153
|
+
virtus (~> 1.0)
|
154
|
+
sass (3.4.18)
|
155
|
+
sexp_processor (4.6.0)
|
156
|
+
shoulda (3.5.0)
|
157
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
158
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
159
|
+
shoulda-context (1.2.1)
|
160
|
+
shoulda-matchers (2.8.0)
|
161
|
+
activesupport (>= 3.0.0)
|
162
|
+
simplecov (0.10.0)
|
163
|
+
docile (~> 1.1.0)
|
164
|
+
json (~> 1.8)
|
165
|
+
simplecov-html (~> 0.10.0)
|
166
|
+
simplecov-html (0.10.0)
|
167
|
+
slim (3.0.6)
|
168
|
+
temple (~> 0.7.3)
|
169
|
+
tilt (>= 1.3.3, < 2.1)
|
170
|
+
slop (3.6.0)
|
171
|
+
sysexits (1.2.0)
|
172
|
+
temple (0.7.6)
|
173
|
+
terminal-table (1.4.5)
|
174
|
+
thread_safe (0.3.5)
|
175
|
+
tilt (2.0.1)
|
176
|
+
timecop (0.8.0)
|
177
|
+
tzinfo (1.2.2)
|
178
|
+
thread_safe (~> 0.1)
|
179
|
+
unparser (0.2.4)
|
180
|
+
abstract_type (~> 0.0.7)
|
181
|
+
adamantium (~> 0.2.0)
|
182
|
+
concord (~> 0.1.5)
|
183
|
+
diff-lcs (~> 1.2.5)
|
184
|
+
equalizer (~> 0.0.9)
|
185
|
+
parser (~> 2.2.2)
|
186
|
+
procto (~> 0.0.2)
|
187
|
+
virtus (1.0.5)
|
188
|
+
axiom-types (~> 0.1)
|
189
|
+
coercible (~> 1.0)
|
190
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
191
|
+
equalizer (~> 0.0, >= 0.0.9)
|
192
|
+
yard (0.8.7.6)
|
193
|
+
|
194
|
+
PLATFORMS
|
195
|
+
ruby
|
196
|
+
|
197
|
+
DEPENDENCIES
|
198
|
+
envlogic!
|
199
|
+
polishgeeks-dev-tools
|
200
|
+
|
201
|
+
BUNDLED WITH
|
202
|
+
1.10.6
|
data/MIT-LICENCE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
2
|
+
a copy of this software and associated documentation files (the
|
3
|
+
"Software"), to deal in the Software without restriction, including
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
7
|
+
the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be
|
10
|
+
included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
16
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Envlogic
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/karafka/envlogic.png)](https://travis-ci.org/karafka/envlogic)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/karafka/envlogic/badges/gpa.svg)](https://codeclimate.com/github/karafka/envlogic)
|
5
|
+
|
6
|
+
Envlogic is a library used to manage environments for your Ruby application in a similar to Rails.env way.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add gem to your Gemfile
|
11
|
+
```ruby
|
12
|
+
gem 'envlogic'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Extend your class or module in which you want to use this library with **Envlogic** module.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
module ExampleModule
|
21
|
+
extend Envlogic
|
22
|
+
# code of this module
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Once you extend your class/module with it, you will have two additional methods (with two aliases):
|
27
|
+
|
28
|
+
- *.env* (.environment) - obtain current env and work with it
|
29
|
+
- *.env=* (.environment=) - set your own environment
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
ExampleModule.env = 'development'
|
33
|
+
ExampleModule.env.development? # => true
|
34
|
+
ExampleModule.env.production? # => false
|
35
|
+
```
|
36
|
+
|
37
|
+
### ENV variables key names and default fallbacks
|
38
|
+
|
39
|
+
#### Application root directory env key name
|
40
|
+
|
41
|
+
By default gem is looking for ENV variable that is based on your application root directory.
|
42
|
+
|
43
|
+
For example, if your application lies in */home/deploy/my_app* it will look for **MY_APP_ENV** variable.
|
44
|
+
|
45
|
+
#### Module/class name based env key name
|
46
|
+
|
47
|
+
If there's no env value under the app directory name key, it will fallback to the module/class based env variable name (including the whole namespace chain):
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
module Basic
|
51
|
+
module Karafka
|
52
|
+
extend Envlogic
|
53
|
+
# code of Karafka module
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
ENV['FACEBOOK_API_ENV'] = nil
|
60
|
+
ENV['BASIC_KARAFKA_ENV'] = 'development'
|
61
|
+
|
62
|
+
Basic::Karafka.env.production? # => false
|
63
|
+
Basic::Karafka.env.development? # => true
|
64
|
+
```
|
65
|
+
|
66
|
+
#### Default fallbacks
|
67
|
+
|
68
|
+
If there's no other way to determine the environment, Envlogic will fallback to ENV['RACK_ENV'] and if it fails, it will just assume that we're in 'development' mode.
|
69
|
+
|
70
|
+
You can also assign the environment directly in Ruby:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
module Basic
|
74
|
+
module Karafka
|
75
|
+
extend Envlogic
|
76
|
+
# code of Karafka module
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
Basic::Karafka.env = :development
|
81
|
+
Basic::Karafka.env.production? # => false
|
82
|
+
Basic::Karafka.env.development? # => true
|
83
|
+
```
|
84
|
+
|
85
|
+
## References
|
86
|
+
|
87
|
+
* [Karafka framework](https://github.com/karafka/karafka)
|
88
|
+
* [Waterdrop](https://github.com/karafka/waterdrop)
|
89
|
+
* [Envlogic](https://github.com/karafka/envlogic)
|
90
|
+
* [Sidekiq Glass](https://github.com/karafka/sidekiq-glass)
|
91
|
+
|
92
|
+
## Note on Patches/Pull Requests
|
93
|
+
|
94
|
+
Fork the project.
|
95
|
+
Make your feature addition or bug fix.
|
96
|
+
Add tests for it. This is important so I don't break it in a future version unintentionally.
|
97
|
+
Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull). Send me a pull request. Bonus points for topic branches.
|
98
|
+
|
99
|
+
Each pull request must pass our quality requirements. To check if everything is as it should be, we use [PolishGeeks Dev Tools](https://github.com/polishgeeks/polishgeeks-dev-tools) that combine multiple linters and code analyzers. Please run:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
bundle exec rake
|
103
|
+
```
|
104
|
+
|
105
|
+
to check if everything is in order. After that you can submit a pull request.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake'
|
4
|
+
require 'polishgeeks-dev-tools'
|
5
|
+
|
6
|
+
PolishGeeks::DevTools.setup do |config|
|
7
|
+
config.brakeman = false
|
8
|
+
config.haml_lint = false
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Self check using polishgeeks-dev-tools'
|
12
|
+
task :check do
|
13
|
+
PolishGeeks::DevTools::Runner.new.execute(
|
14
|
+
PolishGeeks::DevTools::Logger.new
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :check
|
data/envlogic.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'rake'
|
4
|
+
require 'envlogic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "envlogic"
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.version = Envlogic::VERSION
|
10
|
+
spec.authors = ['pavlo_vavruk', 'Maciej Mensfeld']
|
11
|
+
spec.email = %w( pavlo.vavruk@gmail.com maciej@mensfeld.pl )
|
12
|
+
|
13
|
+
spec.summary = %q{ Ruby based library which allows to set and get environments values
|
14
|
+
and easily check environment }
|
15
|
+
spec.description = %q{ Library used to manage environments for your Ruby application }
|
16
|
+
spec.homepage = 'https://github.com/karafka/envlogic'
|
17
|
+
|
18
|
+
spec.add_dependency 'activesupport'
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = %w( lib )
|
22
|
+
end
|
data/lib/envlogic.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
%w(
|
2
|
+
active_support/inflector
|
3
|
+
active_support/string_inquirer
|
4
|
+
envlogic/version
|
5
|
+
envlogic/string_refinements
|
6
|
+
envlogic/env
|
7
|
+
).each { |lib| require lib }
|
8
|
+
|
9
|
+
# Main module that encapsulates logic that should be used to extend any class/module
|
10
|
+
# @note This module should be extended into the class/module in which we want to have env support
|
11
|
+
# @example Use it in RandomClass class
|
12
|
+
# class RandomClass
|
13
|
+
# extend Envlogic
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# RandomClass.env #=> Envlogic::Env instance
|
17
|
+
# RandomClass.env.production? #=> false
|
18
|
+
# RandomClass.env.development? #=> true
|
19
|
+
module Envlogic
|
20
|
+
# @return [Envlogic::Env] envlogic env instance that allows us to check environment
|
21
|
+
# @example Invoke env in TestClass
|
22
|
+
# TestClass.env #=> Envlogic::Env instance
|
23
|
+
def env
|
24
|
+
@env ||= Envlogic::Env.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param environment [String, Symbol] new environment that we want to set
|
28
|
+
# @return [Envlogic::Env] envlogic env instance
|
29
|
+
# @example Assign new environment to MyApp
|
30
|
+
# MyApp.env = :production
|
31
|
+
def env=(environment)
|
32
|
+
env.update(environment.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
# We alias this for backword compatibility with some code that uses full names
|
36
|
+
alias_method :environment, :env
|
37
|
+
alias_method :environment=, :env=
|
38
|
+
end
|
data/lib/envlogic/env.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Main module
|
2
|
+
module Envlogic
|
3
|
+
# Env module to get and set environment
|
4
|
+
class Env < ActiveSupport::StringInquirer
|
5
|
+
using StringRefinements
|
6
|
+
|
7
|
+
# What environment key should be used by default
|
8
|
+
FALLBACK_ENV_KEY = 'RACK_ENV'
|
9
|
+
# What default environment should be asumed when there's nothing else
|
10
|
+
FALLBACK_ENV = 'development'
|
11
|
+
|
12
|
+
# @param klass [Class, Module] class/module for which we want to build a Envlogic::Env object
|
13
|
+
# @return [Envlogic::Env] envlogic env object]
|
14
|
+
# @example
|
15
|
+
# Envlogic::Env.new(User)
|
16
|
+
# @note Will load appropriate environment automatically
|
17
|
+
def initialize(klass)
|
18
|
+
env = ENV[app_dir_name.to_env_key]
|
19
|
+
env ||= ENV[klass.to_s.to_env_key]
|
20
|
+
env ||= ENV[FALLBACK_ENV_KEY]
|
21
|
+
|
22
|
+
update(env || FALLBACK_ENV)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param environment [String] new environment that we want to set
|
26
|
+
# @example
|
27
|
+
# env.update('production')
|
28
|
+
def update(environment)
|
29
|
+
replace(
|
30
|
+
ActiveSupport::StringInquirer.new(environment)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# @return [String] name of the directory in which this application is
|
37
|
+
# @note Will return only the last part, so if the dir is /home/apps/my_app it will
|
38
|
+
# only return the 'my_app' part
|
39
|
+
def app_dir_name
|
40
|
+
Pathname.new(ENV['BUNDLE_GEMFILE'])
|
41
|
+
.dirname
|
42
|
+
.basename
|
43
|
+
.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Envlogic
|
2
|
+
# String refinements used in this library
|
3
|
+
module StringRefinements
|
4
|
+
# Postfix for ENV keys
|
5
|
+
ENV_KEY_POSTFIX = '_ENV'
|
6
|
+
|
7
|
+
refine String do
|
8
|
+
# Converts any string into a bash ENV key
|
9
|
+
def to_env_key
|
10
|
+
underscore
|
11
|
+
.tr('/', '_')
|
12
|
+
.upcase + Envlogic::StringRefinements::ENV_KEY_POSTFIX
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envlogic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pavlo_vavruk
|
8
|
+
- Maciej Mensfeld
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
description: " Library used to manage environments for your Ruby application "
|
29
|
+
email:
|
30
|
+
- pavlo.vavruk@gmail.com
|
31
|
+
- maciej@mensfeld.pl
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- ".ruby-gemset"
|
38
|
+
- ".ruby-version"
|
39
|
+
- ".travis.yml"
|
40
|
+
- Gemfile
|
41
|
+
- Gemfile.lock
|
42
|
+
- MIT-LICENCE
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- envlogic.gemspec
|
46
|
+
- lib/envlogic.rb
|
47
|
+
- lib/envlogic/env.rb
|
48
|
+
- lib/envlogic/string_refinements.rb
|
49
|
+
- lib/envlogic/version.rb
|
50
|
+
homepage: https://github.com/karafka/envlogic
|
51
|
+
licenses: []
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.4.8
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Ruby based library which allows to set and get environments values and easily
|
73
|
+
check environment
|
74
|
+
test_files: []
|
75
|
+
has_rdoc:
|