envvar-rails 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44260b9c093047f0e080dc69d151e6b7c54adb62
4
+ data.tar.gz: 0f9ea3649146060be29932af44a55ebf47fceaac
5
+ SHA512:
6
+ metadata.gz: 9847d4aa72d57927cc8d40f533c6240be2273e42374c56f2be667343c38cc5572a3bec77226b4afdf22e146bd5c3558ecf4f71267ad8e2109289125f1358d6b0
7
+ data.tar.gz: 7f2e905e6842272548daa1e6ef996cf026d4d3a88770430b1091c9fcf98bf075d43f617f794cca1dd4c0a56e1aa32be64772205aa63d4b39b0427afcf3c51a42
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Brendan Stennett
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ # Envvar
2
+
3
+ Manages defining optional (and default) values, environment specific values and required values.
4
+ There is a focus on 12 Factor principle and definining most variables outside of the environment
5
+ in production but making it easy for developers to get started with development environment
6
+ specific variables and sensible defaults.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'envvar'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install envvar
23
+
24
+ ## Usage
25
+
26
+ Place the following lines as soon as possible in the application boot process:
27
+ ```ruby
28
+ require 'envvar'
29
+ Envvar.load(File.expand_path('../application.yml', __FILE__))
30
+ ```
31
+
32
+ The application.yml file contains a few different sections:
33
+ - required
34
+ - defaults
35
+ - development, test, etc.
36
+
37
+ A sample of this file is show below:
38
+ ```yaml
39
+ required:
40
+ - FOO
41
+ - BAR
42
+ defaults:
43
+ BAM: thud
44
+ development:
45
+ FOO: bat
46
+ BAR: qux
47
+ ```
48
+
49
+ This gives a nice place to set application defaults and development/test variables in one place. It would be best
50
+ practise to not include the production environment variables in this file and instead set them as ENV variables in the
51
+ outside environment. Any variables listed in the `required` section that are not present in the ENV hash after the
52
+ Envvar.load call with raise `Envvar::EnvironmentError`. This allows for a fast-fail setup which is useful in more
53
+ complex applications with quite a few necessary environment variables.
54
+
55
+ ## Development
56
+
57
+ 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.
58
+
59
+ 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).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/envvar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+
@@ -0,0 +1 @@
1
+ require 'envvar/rails'
@@ -0,0 +1,6 @@
1
+ # Taken from the nicely put together gem "dotenv" that I have used in the past
2
+ # but doesn't functions a bit different than what I am looking for here.
3
+ # https://github.com/bkeepers/dotenv
4
+
5
+ require 'envvar/rails'
6
+ Envvar::Railtie.load
@@ -0,0 +1,53 @@
1
+ require 'envvar'
2
+
3
+ # Taken from the nicely put together gem "dotenv" that I have used in the past
4
+ # but doesn't functions a bit different than what I am looking for here.
5
+ # https://github.com/bkeepers/dotenv
6
+
7
+ # Fix for rspec rake tasks loading in development
8
+ #
9
+ # Dotenv loads environment variables when the Rails application is initialized.
10
+ # When running `rake`, the Rails application is initialized in development.
11
+ # Rails includes some hacks to set `RAILS_ENV=test` when running `rake test`,
12
+ # but rspec does not include the same hacks.
13
+ #
14
+ # See https://github.com/bkeepers/dotenv/issues/219
15
+ if defined?(Rake.application)
16
+ is_running_specs = Rake.application.top_level_tasks.grep(/^spec(:|$)/).any?
17
+ Rails.env = ENV['RAILS_ENV'] ||= 'test' if is_running_specs
18
+ end
19
+
20
+ module Envvar
21
+ # Dotenv Railtie for using Dotenv to load environment from a file into
22
+ # Rails applications
23
+ class Railtie < Rails::Railtie
24
+ # Public: Load dotenv
25
+ #
26
+ # This will get called during the `before_configuration` callback, but you
27
+ # can manually call `Dotenv::Railtie.load` if you needed it sooner.
28
+ def load
29
+ Envvar.load(config_file, Rails.env)
30
+ end
31
+
32
+ # Internal: `Rails.root` is nil in Rails 4.1 before the application is
33
+ # initialized, so this falls back to the `RAILS_ROOT` environment variable,
34
+ # or the current working directory.
35
+ def root
36
+ Rails.root || Pathname.new(ENV['RAILS_ROOT'] || Dir.pwd)
37
+ end
38
+
39
+ # Rails uses `#method_missing` to delegate all class methods to the
40
+ # instance, which means `Kernel#load` gets called here. We don't want that.
41
+ def self.load
42
+ instance.load
43
+ end
44
+
45
+ config.before_configuration { load }
46
+
47
+ private
48
+
49
+ def config_file
50
+ root.join('config/application.yml')
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: envvar-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Brendan Stennett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: envvar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.1'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3.2'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.12'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: Rails integration for envvar
90
+ email:
91
+ - brendan@thinkdataworks.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - LICENSE
97
+ - README.md
98
+ - lib/envvar-rails.rb
99
+ - lib/envvar/rails-now.rb
100
+ - lib/envvar/rails.rb
101
+ homepage: http://github.com/HuffMoody/envvar
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Rails integration for envvar
126
+ test_files: []