hood 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +6 -0
- data/README.md +22 -4
- data/lib/hood/dsl.rb +36 -10
- data/lib/hood/railtie.rb +7 -0
- data/lib/hood/variable.rb +23 -1
- data/lib/hood/version.rb +1 -1
- data/lib/hood.rb +27 -1
- metadata +9 -6
data/HISTORY.md
ADDED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Hood
|
2
2
|
|
3
|
-
|
4
|
-
our specs are weak, and there are probably bugs
|
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
5
|
|
6
6
|
Hood is to enviroment variables as bundler is to gems. To put it simply, we have
|
7
7
|
the following goals:
|
@@ -17,7 +17,11 @@ Hood uses something called an "Envfile" to define environment variables. It uses
|
|
17
17
|
a DSL (Domain Specific Language) similar to Bundler's to do so:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
env "GOOGLE_MAPS_API_KEY"
|
20
|
+
env "GOOGLE_MAPS_API_KEY"
|
21
|
+
|
22
|
+
env "REDIS_URI", :default => "localhost:6379"
|
23
|
+
|
24
|
+
env "SALES_TAX", :description => "Current sales tax in Los Angeles (eg. 0.0875)"
|
21
25
|
|
22
26
|
prefix "DB_" do
|
23
27
|
env "PASSWORD"
|
@@ -31,5 +35,19 @@ end
|
|
31
35
|
## Options
|
32
36
|
* :description - If the desired value isn't obvious, you can include a string
|
33
37
|
* :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
38
|
* :default - A pre-defined default value for this var
|
39
|
+
|
40
|
+
## Compatibility
|
41
|
+
|
42
|
+
Hood is tested against the following Rubies: MRI 1.8.7, MRI 1.9.2, MRI 1.9.3,
|
43
|
+
Rubinius 2.0, and JRuby.
|
44
|
+
|
45
|
+
![Build Status](https://secure.travis-ci.org/bloudermilk/hood.png?branch=master&.png)
|
46
|
+
|
47
|
+
[Build History](http://travis-ci.org/#!/bloudermilk/hood)
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
Hood is released under the MIT license. See the LICENSE file for more
|
53
|
+
info.
|
data/lib/hood/dsl.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
module Hood
|
2
2
|
class DSL
|
3
|
+
VALID_OPTION_KEYS = [:default, :description, :optional]
|
4
|
+
|
5
|
+
attr_reader :variables
|
6
|
+
|
3
7
|
def self.evaluate(envfile)
|
4
8
|
builder = new
|
5
|
-
|
9
|
+
builder.instance_eval(Hood.read_file(envfile.to_s), envfile.to_s, 1)
|
10
|
+
builder
|
6
11
|
end
|
7
12
|
|
8
13
|
def initialize
|
@@ -11,10 +16,23 @@ module Hood
|
|
11
16
|
@prefix = ""
|
12
17
|
end
|
13
18
|
|
19
|
+
def exists?(name)
|
20
|
+
!!@variables.index {|v| v.name == name }
|
21
|
+
end
|
22
|
+
|
14
23
|
def env(name, opts={})
|
15
|
-
_normalize_options(name, opts)
|
24
|
+
name, opts = _normalize_options(name, opts)
|
16
25
|
|
17
26
|
var = Variable.new(name, opts)
|
27
|
+
|
28
|
+
if exists? var.name
|
29
|
+
message = "You tried to define the variable '#{var.name}' twice."
|
30
|
+
raise DuplicateVariableError, message
|
31
|
+
end
|
32
|
+
|
33
|
+
@variables << var
|
34
|
+
|
35
|
+
var
|
18
36
|
end
|
19
37
|
|
20
38
|
def optional
|
@@ -24,7 +42,7 @@ module Hood
|
|
24
42
|
@optional = old
|
25
43
|
end
|
26
44
|
|
27
|
-
def prefix(prefix)
|
45
|
+
def prefix(prefix, &block)
|
28
46
|
@prefix, old = @prefix + prefix, @prefix
|
29
47
|
yield
|
30
48
|
ensure
|
@@ -36,10 +54,10 @@ module Hood
|
|
36
54
|
def _normalize_hash(opts)
|
37
55
|
# Cannot modify a hash during an iteration in 1.9
|
38
56
|
opts.keys.each do |k|
|
39
|
-
next if
|
57
|
+
next if k.is_a? Symbol
|
40
58
|
v = opts[k]
|
41
59
|
opts.delete(k)
|
42
|
-
opts[k.
|
60
|
+
opts[k.to_sym] = v
|
43
61
|
end
|
44
62
|
opts
|
45
63
|
end
|
@@ -47,17 +65,25 @@ module Hood
|
|
47
65
|
def _normalize_options(name, opts)
|
48
66
|
_normalize_hash(opts)
|
49
67
|
|
50
|
-
invalid_keys = opts.keys -
|
68
|
+
invalid_keys = opts.keys - VALID_OPTION_KEYS
|
51
69
|
if invalid_keys.any?
|
52
70
|
plural = invalid_keys.size > 1
|
53
|
-
message = "You passed #{invalid_keys.map{|k|
|
71
|
+
message = "You passed #{invalid_keys.map{|k| ":#{k}" }.join(", ")} "
|
54
72
|
if plural
|
55
|
-
message << "as options for
|
73
|
+
message << "as options for variable '#{name}', but they are invalid."
|
56
74
|
else
|
57
|
-
message << "as an option for
|
75
|
+
message << "as an option for variable '#{name}', but it is invalid."
|
58
76
|
end
|
59
|
-
raise
|
77
|
+
raise InvalidOptionError, message
|
60
78
|
end
|
79
|
+
|
80
|
+
# The :optional option should default to the builder's state
|
81
|
+
opts[:optional] = @optional if opts[:optional].nil?
|
82
|
+
|
83
|
+
# Prepend the prefix
|
84
|
+
name = @prefix + name
|
85
|
+
|
86
|
+
[name, opts]
|
61
87
|
end
|
62
88
|
end
|
63
89
|
end
|
data/lib/hood/railtie.rb
ADDED
data/lib/hood/variable.rb
CHANGED
@@ -1,7 +1,29 @@
|
|
1
1
|
module Hood
|
2
2
|
class Variable
|
3
|
+
attr_reader :name, :description, :default
|
4
|
+
|
3
5
|
def initialize(name, opts={})
|
4
|
-
@name
|
6
|
+
@name = name
|
7
|
+
@default = opts[:default]
|
8
|
+
@description = opts[:description]
|
9
|
+
@optional = !!opts[:optional]
|
10
|
+
end
|
11
|
+
|
12
|
+
def optional?
|
13
|
+
@optional
|
14
|
+
end
|
15
|
+
|
16
|
+
def fulfill!
|
17
|
+
ENV[name] ||= @default
|
18
|
+
|
19
|
+
unless valid?
|
20
|
+
message = "Missing required environment variable '#{name}'"
|
21
|
+
raise UnfulfilledVariableError, message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid?
|
26
|
+
!!ENV[name] || optional?
|
5
27
|
end
|
6
28
|
end
|
7
29
|
end
|
data/lib/hood/version.rb
CHANGED
data/lib/hood.rb
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
module Hood
|
2
2
|
autoload :DSL, "hood/dsl"
|
3
|
-
autoload :Variable, "hood/
|
3
|
+
autoload :Variable, "hood/variable"
|
4
|
+
autoload :VERSION, "hood/version"
|
4
5
|
|
6
|
+
class HoodError < StandardError ; end
|
7
|
+
class DslError < HoodError ; end
|
8
|
+
class InvalidOptionError < DslError ; end
|
9
|
+
class DuplicateVariableError < DslError ; end
|
10
|
+
class UnfulfilledVariableError < HoodError ; end
|
5
11
|
|
12
|
+
class << self
|
13
|
+
def read_file(file)
|
14
|
+
File.open(file, "rb") { |f| f.read }
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup!
|
18
|
+
load_envfile
|
19
|
+
fulfull_requirements
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_envfile
|
23
|
+
@builder = DSL.evaluate("Envfile")
|
24
|
+
end
|
25
|
+
|
26
|
+
def fulfill_requirements
|
27
|
+
@builder.variables.each(&:fulfill!)
|
28
|
+
end
|
29
|
+
end
|
6
30
|
end
|
31
|
+
|
32
|
+
require "hood/railtie" if defined?(Rails)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hood
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Hood gives you a standard way to define environment variable requirements
|
15
|
+
for your app.
|
15
16
|
email:
|
16
17
|
- brendan@gophilosophie.com
|
17
18
|
executables: []
|
@@ -19,9 +20,11 @@ extensions: []
|
|
19
20
|
extra_rdoc_files: []
|
20
21
|
files:
|
21
22
|
- lib/hood/dsl.rb
|
23
|
+
- lib/hood/railtie.rb
|
22
24
|
- lib/hood/variable.rb
|
23
25
|
- lib/hood/version.rb
|
24
26
|
- lib/hood.rb
|
27
|
+
- HISTORY.md
|
25
28
|
- LICENSE
|
26
29
|
- Rakefile
|
27
30
|
- README.md
|
@@ -39,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
42
|
version: '0'
|
40
43
|
segments:
|
41
44
|
- 0
|
42
|
-
hash:
|
45
|
+
hash: -1841366577289620485
|
43
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
47
|
none: false
|
45
48
|
requirements:
|
@@ -48,11 +51,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
51
|
version: '0'
|
49
52
|
segments:
|
50
53
|
- 0
|
51
|
-
hash:
|
54
|
+
hash: -1841366577289620485
|
52
55
|
requirements: []
|
53
56
|
rubyforge_project:
|
54
57
|
rubygems_version: 1.8.10
|
55
58
|
signing_key:
|
56
59
|
specification_version: 3
|
57
|
-
summary:
|
60
|
+
summary: Hood is the easiest way to manage your applications environment variables.
|
58
61
|
test_files: []
|