env_loader 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32ae6d75fb3dceb6dd877846c61d99ed9fe6ec78
4
- data.tar.gz: 735ab2959cb12459fc0b3780f97627ee90f67c62
3
+ metadata.gz: 7bf9112a103965a07c8a3c1bb164c4e87dcc8161
4
+ data.tar.gz: 0636cf83d8f73eb02e821db1470b5b368860e2bc
5
5
  SHA512:
6
- metadata.gz: f2f232f7e4a864e55a5b12f8c9ba0127b0ea0230f1389aa478abe51b046932941ae3982de6d441ff799e2bfe3526dfc044fe8c6476217f9f0d8e830137f3de39
7
- data.tar.gz: 60148c44dec0e660f10badb02c78eedb515b3959ecc3ec30dfecf8b4d2ea11f816a5d327abc552359b8748dcd5939900bd23b9b4c4d72f241d252df9f0f1ff58
6
+ metadata.gz: 18f5583f655fd024566ad4159d1b9db41d37db4754ec7717cfd6969290e6a709d25c577f852a8f87fbc8265f0d7fffcf0b5d7607574ed2cd7ad2f3d67f5c7285
7
+ data.tar.gz: 08873040504616d900db77f6cc782554d2331cf7269b61f40e77af81702efefccad980c5e39d8c7158b5e2b162b078f75bd5e7be071c63cc54f483bf757d588d
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # EnvLoader
2
2
 
3
- TODO: Write a gem description
3
+ By: Endri Gjiri *www.name-reaction.com*
4
+
5
+ **EnvLoader** is a utility module with a single `read` method which can read a .yml file and store its data in environment variables. This is useful when dealing with sensitive data that should not be directly entered in the code and stored in version control. Passwords and other information can now simply be stored in a yaml file which is added to .gitignore and then can be accessed through the env_loader gem via ENV variables
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,7 +20,40 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ 1. Include the env_loader gem directly or through bundler
24
+ ```ruby
25
+ require 'env_loader'
26
+ ```
27
+
28
+ 2. Create a .yml file with all the desired information. For example create a file called credentials.yml with the following content:
29
+ ```yml
30
+ username: endri
31
+ password: secret
32
+ ```
33
+
34
+ 3. Read the .yml file through the env_loader gem as follows:
35
+ ```ruby
36
+ EnvLoader.read('credentials.yml')
37
+ ```
38
+
39
+ The data is now available through Ruby's ENV accessor. Always user uppercase strings as the key even though they were lowercase in the .yml file, for example:
40
+ ```ruby
41
+ ENV['USERNAME'] # => "endri"
42
+ ENV['PASSWORD'] # => "secret"
43
+ ```
44
+
45
+ ## Usage with Rails
46
+
47
+ 1. Add the env_loader gem to the Gemfile and run `Bundle install`
48
+
49
+ 2. Create a file called *env_variables.yml* in the *config* directory with the desired data. This is the default path where the gem will look in and does not require passing in the path to the `read` method
50
+
51
+ 3. Read the .yml file through the env_loader gem by adding the following line to *config/application.rb*
52
+ ```ruby
53
+ EnvLoader.read
54
+ ```
55
+
56
+ The data can now be accessed throughout the Rails app using `ENV['KEY']` as explaied above.
22
57
 
23
58
  ## Contributing
24
59
 
@@ -1,3 +1,3 @@
1
1
  module EnvLoader
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/env_loader.rb CHANGED
@@ -1,13 +1,13 @@
1
- require "env_loader/version"
1
+ require 'env_loader/version'
2
2
  require 'yaml'
3
3
 
4
4
  module EnvLoader
5
5
 
6
- def self.read(env_yml_file)
6
+ def self.read(env_yml_file = File.join('config', 'env_variables.yml'))
7
7
  if File.exists? env_yml_file
8
8
  if hash = YAML.load(File.open env_yml_file)
9
9
  hash.each do |key, value|
10
- ENV[key.upcase] = value
10
+ ENV[key.upcase] = value.to_s if value
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Endri Gjiri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2014-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 2.0.3
76
+ rubygems_version: 2.0.14
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Reads a YAML file and creates ENV variables from it