envious 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/envious.gemspec +13 -0
- data/lib/envious.rb +34 -0
- data/lib/envious/railtie.rb +7 -0
- data/lib/generators/envious/setup_generator.rb +15 -0
- data/lib/generators/envious/templates/environment_vars.yml +15 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ryan Nielson
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Envious
|
2
|
+
|
3
|
+
Easy Ruby on Rails application and environment configuration.
|
4
|
+
|
5
|
+
## What is Envious?
|
6
|
+
Envious is used to configure environment variables for Ruby on Rails 3 applications. It allows you to add configuration variables without the need to add configuration files to your repository.
|
7
|
+
|
8
|
+
Envious works by supplying your with an `environment_vars.yml` configuration file. When your Rails app is loaded, configurations options from this file are also loaded and added to the local Environment variable hash. The configuration options can then be accessed using the `ENV[KEY]` syntax.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'envious'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install envious
|
23
|
+
|
24
|
+
After installation, run the following to create `config/environment_vars.yml`, and add it to your `.gitignore`.
|
25
|
+
|
26
|
+
$ rails generate envious:setup
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Setting up configuration with Envious is easy. To begin, simply add some variables to your `config/environment_vars.yml` that you would like available in the `ENV` hash. Keep in mind that Envious uses `Rails.env` to allow configuration based on your current environment.
|
31
|
+
```yaml
|
32
|
+
development:
|
33
|
+
USERNAME: "cat"
|
34
|
+
|
35
|
+
production:
|
36
|
+
USERNAME: "dog"
|
37
|
+
|
38
|
+
API_KEY: "ABCXYZ"
|
39
|
+
```
|
40
|
+
In the above case, `ENV["API_KEY"]` will produce `"ABCXYZ"` because any values not under an environment will be available in all environments. In development `ENV["USERNAME"]` will be `"cat", and it will be `"dog"` in production.
|
41
|
+
|
42
|
+
Since Envious configuration is loaded when your Rails app loads, the `ENV` hash is available anywhere in your application where you may need to call upon your configuration.
|
43
|
+
|
44
|
+
|
45
|
+
## Questions or Problems?
|
46
|
+
|
47
|
+
If you have any questions or issues with Envious, please add an [issue on GitHub](https://github.com/RyanNielson/envious/issues), or send a pull request.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/envious.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "envious"
|
3
|
+
gem.version = "0.1.0"
|
4
|
+
gem.authors = ["Ryan Nielson"]
|
5
|
+
gem.email = ["ryan.nielson@gmail.com"]
|
6
|
+
gem.description = %q{Easy Ruby on Rails application and environment configuration.}
|
7
|
+
gem.summary = %q{Easy Ruby on Rails application and environment configuration using YAML and ENV.}
|
8
|
+
gem.homepage = "http://github.com/ryannielson/envious"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($/)
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
end
|
data/lib/envious.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "envious/railtie"
|
2
|
+
|
3
|
+
module Envious
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def load_env(specific_environment = nil)
|
7
|
+
environment = (specific_environment || self.environment).to_s
|
8
|
+
add_to_environment(default_vars.merge(environment_vars))
|
9
|
+
end
|
10
|
+
|
11
|
+
def file
|
12
|
+
@file ||= Rails.root.join('config/environment_vars.yml')
|
13
|
+
end
|
14
|
+
|
15
|
+
def yaml
|
16
|
+
@yaml ||= File.exist?(file) ? YAML.load(File.read(file)) : {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def environment
|
20
|
+
Rails.env
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_vars()
|
24
|
+
yaml.reject { |_, v| Hash === v }
|
25
|
+
end
|
26
|
+
|
27
|
+
def environment_vars
|
28
|
+
yaml.fetch(environment)
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_to_environment(hash)
|
32
|
+
hash.each { |key, value| ENV[key.to_s] = value.to_s }
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Envious
|
2
|
+
module Generators
|
3
|
+
class SetupGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def copy_environment_vars_file
|
7
|
+
copy_file 'environment_vars.yml', 'config/environment_vars.yml'
|
8
|
+
end
|
9
|
+
|
10
|
+
def configure_gitignore
|
11
|
+
append_file('.gitignore', '/config/environment_vars.yml') if File.exists?('.gitignore')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Add environmental variables to this file in yaml format:
|
2
|
+
#
|
3
|
+
# development:
|
4
|
+
# USERNAME: "cat"
|
5
|
+
# PASSWORD: "secret"
|
6
|
+
#
|
7
|
+
# production:
|
8
|
+
# USERNAME: "dog"
|
9
|
+
# PASSWORD: "stillsecret"
|
10
|
+
#
|
11
|
+
# API_KEY: "ABCXYZ"
|
12
|
+
# SECRET: "HELLO"
|
13
|
+
#
|
14
|
+
# Envious supports Rails environments so anything under production will only be loaded into the environment in production, and anything under development will only be loaded in the development environment.
|
15
|
+
# Anything outside of an environment will be loaded no matter which Rails environment you're in.
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envious
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Nielson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Easy Ruby on Rails application and environment configuration.
|
15
|
+
email:
|
16
|
+
- ryan.nielson@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- envious.gemspec
|
27
|
+
- lib/envious.rb
|
28
|
+
- lib/envious/railtie.rb
|
29
|
+
- lib/generators/envious/setup_generator.rb
|
30
|
+
- lib/generators/envious/templates/environment_vars.yml
|
31
|
+
homepage: http://github.com/ryannielson/envious
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.24
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Easy Ruby on Rails application and environment configuration using YAML and
|
55
|
+
ENV.
|
56
|
+
test_files: []
|