hood 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +7 -0
- data/README.md +35 -0
- data/Rakefile +22 -0
- data/lib/hood/dsl.rb +63 -0
- data/lib/hood/variable.rb +7 -0
- data/lib/hood/version.rb +3 -0
- data/lib/hood.rb +6 -0
- metadata +58 -0
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2011 Brendan Loudermilk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Hood
|
2
|
+
|
3
|
+
*Hood is currently in alpha development. Our feature-set isn't fully developed,
|
4
|
+
our specs are weak, and there are probably bugs.*
|
5
|
+
|
6
|
+
Hood is to enviroment variables as bundler is to gems. To put it simply, we have
|
7
|
+
the following goals:
|
8
|
+
|
9
|
+
* Serve as a means to document all enviroment variables for a given Ruby or
|
10
|
+
Rails project.
|
11
|
+
* Give developers an easy way to ensure the presence of required variables
|
12
|
+
* Streamline the process of bootstrapping a new environment
|
13
|
+
|
14
|
+
## Envfile
|
15
|
+
|
16
|
+
Hood uses something called an "Envfile" to define environment variables. It uses
|
17
|
+
a DSL (Domain Specific Language) similar to Bundler's to do so:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
env "GOOGLE_MAPS_API_KEY", required: true
|
21
|
+
|
22
|
+
prefix "DB_" do
|
23
|
+
env "PASSWORD"
|
24
|
+
env "USER"
|
25
|
+
env "DATABASE"
|
26
|
+
env "SOCKET"
|
27
|
+
env "ADAPTER"
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Options
|
32
|
+
* :description - If the desired value isn't obvious, you can include a string
|
33
|
+
* :optional - Pass true to avoid throwing a runtime error when the app starts and this var isn't present
|
34
|
+
* :prefix - Prefixes the group (or env I guess) with the passed string. Useful when you have a group where all vars have the same prefix
|
35
|
+
* :default - A pre-defined default value for this var
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require "rake"
|
5
|
+
require "rspec"
|
6
|
+
require "rspec/core/rake_task"
|
7
|
+
|
8
|
+
lib_path = File.expand_path("../lib", __FILE__)
|
9
|
+
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include? lib_path
|
10
|
+
|
11
|
+
require "hood/version"
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new("spec")
|
14
|
+
task :default => :spec
|
15
|
+
|
16
|
+
task :build do
|
17
|
+
system "gem build hood.gemspec"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :install => :build do
|
21
|
+
system "gem install hood-#{Hood::VERSION}.gem"
|
22
|
+
end
|
data/lib/hood/dsl.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Hood
|
2
|
+
class DSL
|
3
|
+
def self.evaluate(envfile)
|
4
|
+
builder = new
|
5
|
+
#builder.instance_eval(
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@variables = []
|
10
|
+
@optional = false
|
11
|
+
@prefix = ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def env(name, opts={})
|
15
|
+
_normalize_options(name, opts)
|
16
|
+
|
17
|
+
var = Variable.new(name, opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
def optional
|
21
|
+
@optional, old = true, @optional
|
22
|
+
yield
|
23
|
+
ensure
|
24
|
+
@optional = old
|
25
|
+
end
|
26
|
+
|
27
|
+
def prefix(prefix)
|
28
|
+
@prefix, old = @prefix + prefix, @prefix
|
29
|
+
yield
|
30
|
+
ensure
|
31
|
+
@prefix = old
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def _normalize_hash(opts)
|
37
|
+
# Cannot modify a hash during an iteration in 1.9
|
38
|
+
opts.keys.each do |k|
|
39
|
+
next if String === k
|
40
|
+
v = opts[k]
|
41
|
+
opts.delete(k)
|
42
|
+
opts[k.to_s] = v
|
43
|
+
end
|
44
|
+
opts
|
45
|
+
end
|
46
|
+
|
47
|
+
def _normalize_options(name, opts)
|
48
|
+
_normalize_hash(opts)
|
49
|
+
|
50
|
+
invalid_keys = opts.keys - %w(description prefix optional)
|
51
|
+
if invalid_keys.any?
|
52
|
+
plural = invalid_keys.size > 1
|
53
|
+
message = "You passed #{invalid_keys.map{|k| ':'+k }.join(", ")} "
|
54
|
+
if plural
|
55
|
+
message << "as options for env '#{name}', but they are invalid."
|
56
|
+
else
|
57
|
+
message << "as an option for env '#{name}', but it is invalid."
|
58
|
+
end
|
59
|
+
raise InvalidOption, message
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/hood/version.rb
ADDED
data/lib/hood.rb
ADDED
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hood
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brendan Loudermilk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-31 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Description has not been written yet.
|
15
|
+
email:
|
16
|
+
- brendan@gophilosophie.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/hood/dsl.rb
|
22
|
+
- lib/hood/variable.rb
|
23
|
+
- lib/hood/version.rb
|
24
|
+
- lib/hood.rb
|
25
|
+
- LICENSE
|
26
|
+
- Rakefile
|
27
|
+
- README.md
|
28
|
+
homepage: http://github.com/bloudermilk/hood
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
hash: 2469481964501867426
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
hash: 2469481964501867426
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.10
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Summary has not been written yet
|
58
|
+
test_files: []
|