redis_vars 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # RedisVars
2
+
3
+ Manage environment variables for development teams follows the 12 Factors/Heroku pattern. You will need a shared redis server for your team. I suggest you share a RedisToGo free plan if you are distributed, or use your development redis server if you have one and would prefer that.
4
+
5
+ ## Install
6
+
7
+ gem install redis_vars
8
+
9
+ Set REDIS_VARS_URL for your shell(.profile/.bash_profile/.zprofile/etc):
10
+
11
+ export REDIS_VARS_URL=redis://password@hostname:port/db
12
+
13
+ ## Managing
14
+
15
+ It uses your project directory name as the key, so use consistently named folders for your team. Switch into your project directory and run any of the following commands:
16
+
17
+ redis_vars add TEST_KEY value
18
+ redis_vars list
19
+ redis_vars remove TEST_KEY
20
+
21
+ Every key name is made uppercase, so feel free to be lazy and use all lowercase keys in your management.
22
+
23
+ You can override the key used with an enviroment variable if you want to manage from a different folder:
24
+
25
+ APP_KEY=different_app redis_vars list
26
+
27
+ ## Developing
28
+
29
+ There are two different ways I envision this being used, non-invasive and invasive. Let's start with non-invasive:
30
+
31
+ ### Non-invasive
32
+
33
+ This allows you to export a list of the variables you have stored to a file you use in development. There seems to be the two different formats used places, with and without requiring export. The list command is for without export, and export includes the export. Here are examples if that makes now sense:
34
+
35
+ Forman:
36
+
37
+ redis_vars list > .env
38
+
39
+ rbenv(with rbenv-vars plugin):
40
+
41
+ redis_vars list > .rbenv-vars
42
+
43
+ Pow:
44
+
45
+ redis_vars export > .powenv
46
+
47
+ ### Invasive
48
+
49
+ You can have it load in the environment variables automatically on application start with this method.
50
+
51
+ Gemfile:
52
+
53
+ group :development do
54
+ gem 'redis_vars'
55
+ end
56
+
57
+ config/environments/development.rb:
58
+
59
+ RedisVars.load
60
+
61
+ Note that if you env vars are already set it will not overwrite them. This allows you to do this method in combination with using the non-invasive method to override what is stored in redis.
62
+
63
+ ## Authors
64
+
65
+ #### Created and maintained by
66
+ Daniel Farrell
67
+
68
+ ## License
69
+
70
+ MIT
data/bin/redis_vars ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "redis_vars/cli"
6
+
7
+ RedisVars::CLI.start
@@ -0,0 +1,40 @@
1
+ require "redis_vars/version"
2
+ require "redis_vars/store"
3
+ require "thor"
4
+
5
+ module RedisVars
6
+ class CLI < Thor
7
+
8
+ desc "add KEY VALUE", "Add a new env var"
9
+ def add(key, value)
10
+ store.add key, value
11
+ end
12
+
13
+ desc "remove KEY", "Remove a env var"
14
+ def remove(key)
15
+ store.remove key
16
+ end
17
+
18
+ desc "list", "List the env vars"
19
+ def list
20
+ puts store.list
21
+ end
22
+
23
+ desc "export", "Export env vars"
24
+ def export
25
+ puts store.export
26
+ end
27
+
28
+ desc "version", "Displays gem version"
29
+ def version
30
+ puts VERSION
31
+ end
32
+
33
+ private
34
+
35
+ def store
36
+ @store ||= Store.new
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ module RedisVars
2
+ class Config
3
+ def uri
4
+ ENV['REDIS_VARS_URL']
5
+ end
6
+
7
+ def app_key
8
+ ENV['APP_KEY'] || pwd
9
+ end
10
+
11
+ def pwd
12
+ Dir.pwd.split('/').last
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ require "redis_vars/config"
2
+ require "redis"
3
+
4
+ module RedisVars
5
+ class Store
6
+
7
+ def add(key, value)
8
+ redis.hset app_key, key.upcase, value
9
+ end
10
+
11
+ def remove(key)
12
+ redis.hdel app_key, key.upcase
13
+ end
14
+
15
+ def hash
16
+ redis.hgetall(app_key)
17
+ end
18
+
19
+ def list
20
+ map {|key, val| "#{key.upcase}=#{val}"}.join("\n")
21
+ end
22
+
23
+ def export
24
+ map {|key, val| "export #{key.upcase}=#{val}"}.join("\n")
25
+ end
26
+
27
+ private
28
+
29
+ def map(&block)
30
+ hash.map &block
31
+ end
32
+
33
+ def uri
34
+ config.uri
35
+ end
36
+
37
+ def app_key
38
+ config.app_key
39
+ end
40
+
41
+ def redis
42
+ @redis ||= Redis.new(:uri => uri)
43
+ end
44
+
45
+ def config
46
+ @config ||= Config.new
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module RedisVars
2
+ VERSION = "0.6.0"
3
+ end
data/lib/redis_vars.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "redis_vars/version"
2
+ require "redis_vars/store"
3
+
4
+ module RedisVars
5
+ def self.load
6
+ Store.new.hash.each { |key, value| ENV[key.upcase] = value unless ENV[key.upcase] }
7
+ end
8
+ end
data/man/redis_vars.1 ADDED
@@ -0,0 +1,43 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "REDIS_VARS" "1" "December 2012" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBredis_vars\fR \- manage shared variables
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBredis_vars add <key> <value>\fR
11
+ .
12
+ .br
13
+ \fBredis_vars remove <key>\fR
14
+ .
15
+ .br
16
+ \fBredis_vars list\fR
17
+ .
18
+ .br
19
+ \fBredis_vars export\fR
20
+ .
21
+ .SH "DESCRIPTION"
22
+ RedisVars is a way to manage environment variables for a development team\.
23
+ .
24
+ .SH "ADDING"
25
+ \fBredis_vars add\fR is used to add variables to the redis store\.
26
+ .
27
+ .P
28
+ It requires a key and a value be passed in\.
29
+ .
30
+ .SH "REMOVING"
31
+ \fBredis_vars remove\fR is used to remove a variables from the redis store\.
32
+ .
33
+ .P
34
+ It requires passing in a key\.
35
+ .
36
+ .SH "EXPORTING"
37
+ \fBredis_vars list\fR gives you a list of the variables in a format that will work for a Foreman \.env file or a \.rbenv\-vars file\.
38
+ .
39
+ .P
40
+ \fBredis_vars export\fR gives you a list of the variables in a format that will work for a shell or a Pow \.powenv file\.
41
+ .
42
+ .SH "COPYRIGHT"
43
+ RedisVars is Copyright (C) 2012 Daniel Farrellr \fIhttp://danielfarrell\.com\fR
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_vars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Farrell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.13.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.13.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: redis
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Environment variable handling for teams following 12 Factor/Heroku pattern
47
+ email: danielfarrell76@gmail.com
48
+ executables:
49
+ - redis_vars
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - bin/redis_vars
54
+ - lib/redis_vars/cli.rb
55
+ - lib/redis_vars/config.rb
56
+ - lib/redis_vars/store.rb
57
+ - lib/redis_vars/version.rb
58
+ - lib/redis_vars.rb
59
+ - README.md
60
+ - man/redis_vars.1
61
+ homepage: http://github.com/danielfarrell/redis_vars
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.23
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Environment variable handling for teams following 12 Factor/Heroku pattern
85
+ test_files: []
86
+ has_rdoc: