configlet 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +1 -1
- data/lib/configlet.rb +10 -4
- data/test/test_configlet.rb +24 -20
- metadata +15 -22
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
data/lib/configlet.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
module Configlet
|
6
6
|
|
7
7
|
# What's at the front of our environment variables? This will be
|
8
|
-
# upcased and a trailing
|
8
|
+
# upcased and a trailing underscore will be added, so
|
9
9
|
# <tt>Configlet[:foo]</tt> with a prefix of <tt>thunk</tt> maps to
|
10
10
|
# the <tt>THUNK_FOO</tt> environment variable. Default is +nil+.
|
11
11
|
|
@@ -13,7 +13,7 @@ module Configlet
|
|
13
13
|
|
14
14
|
# Duh.
|
15
15
|
|
16
|
-
VERSION = "1.
|
16
|
+
VERSION = "1.2.0"
|
17
17
|
|
18
18
|
I = lambda { |v| v } #:nodoc:
|
19
19
|
|
@@ -57,16 +57,21 @@ module Configlet
|
|
57
57
|
# Swanky block form. More pleasant to read when setting multiple
|
58
58
|
# defaults, e.g.,
|
59
59
|
#
|
60
|
-
# Configlet.
|
60
|
+
# Configlet.config :myapp do
|
61
61
|
# default "email.from" => "noreply@myapp.com"
|
62
62
|
# default :host => "myapp.local"
|
63
63
|
# end
|
64
64
|
|
65
|
-
def
|
65
|
+
def config prefix, &block
|
66
66
|
self.prefix = prefix
|
67
67
|
instance_eval(&block)
|
68
68
|
end
|
69
69
|
|
70
|
+
def for *args, &block #:nodoc:
|
71
|
+
warn "Configlet.for is deprecated, and will be removed in 2.0."
|
72
|
+
config(*args, &block)
|
73
|
+
end
|
74
|
+
|
70
75
|
# Mess with a value when it's retrieved. Useful for turning untyped
|
71
76
|
# environment strings into numbers, booleans, enums, or class
|
72
77
|
# instances. Here's how to munge a boolean:
|
@@ -88,6 +93,7 @@ module Configlet
|
|
88
93
|
# Set prefix to +nil+, clear defaults and mungers.
|
89
94
|
|
90
95
|
def reset
|
96
|
+
warn "Configlet.reset is deprecated, and will be removed in 2.0."
|
91
97
|
self.prefix = nil
|
92
98
|
|
93
99
|
defaults.clear
|
data/test/test_configlet.rb
CHANGED
@@ -2,55 +2,59 @@ require "minitest/autorun"
|
|
2
2
|
require "configlet"
|
3
3
|
|
4
4
|
class TestConfiglet < MiniTest::Unit::TestCase
|
5
|
+
class Stub
|
6
|
+
include Configlet
|
7
|
+
end
|
8
|
+
|
5
9
|
def setup
|
10
|
+
@cfg = Stub.new
|
6
11
|
@env = ENV.to_hash
|
7
|
-
Configlet.reset
|
8
12
|
end
|
9
13
|
|
10
14
|
def teardown
|
11
15
|
ENV.replace @env
|
12
16
|
end
|
13
17
|
|
14
|
-
def
|
15
|
-
assert_nil Configlet["foo"]
|
16
|
-
|
17
|
-
Configlet.default :foo => "bar"
|
18
|
-
assert_equal "bar", Configlet["foo"]
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_for
|
18
|
+
def test_config
|
22
19
|
ENV["PREFIX_FOO"] = "bar"
|
23
20
|
|
24
|
-
|
21
|
+
@cfg.config :prefix do
|
25
22
|
default :bar => "baz"
|
26
23
|
end
|
27
24
|
|
28
|
-
assert_equal "bar",
|
29
|
-
assert_equal "baz",
|
25
|
+
assert_equal "bar", @cfg[:foo]
|
26
|
+
assert_equal "baz", @cfg[:bar]
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_default
|
30
|
+
assert_nil @cfg["foo"]
|
31
|
+
|
32
|
+
@cfg.default :foo => "bar"
|
33
|
+
assert_equal "bar", @cfg["foo"]
|
30
34
|
end
|
31
35
|
|
32
36
|
def test_get
|
33
37
|
ENV["FOO"] = "bar"
|
34
|
-
assert_equal "bar",
|
38
|
+
assert_equal "bar", @cfg[:foo]
|
35
39
|
|
36
|
-
|
40
|
+
@cfg.prefix = "boom"
|
37
41
|
ENV["BOOM_FOO"] = "bar"
|
38
|
-
assert_equal "bar",
|
42
|
+
assert_equal "bar", @cfg[:foo]
|
39
43
|
end
|
40
44
|
|
41
45
|
def test_munge
|
42
46
|
ENV["STUPID"] = "true"
|
43
|
-
|
44
|
-
assert_equal true,
|
47
|
+
@cfg.munge(:stupid) { |v| "true" == v }
|
48
|
+
assert_equal true, @cfg[:stupid]
|
45
49
|
end
|
46
50
|
|
47
51
|
def test_set
|
48
52
|
assert_nil ENV["FOO"]
|
49
|
-
|
53
|
+
@cfg[:foo] = "bar"
|
50
54
|
assert_equal "bar", ENV["FOO"]
|
51
55
|
|
52
|
-
|
53
|
-
|
56
|
+
@cfg.prefix = "pow"
|
57
|
+
@cfg[:thud] = "zap"
|
54
58
|
assert_equal "zap", ENV["POW_THUD"]
|
55
59
|
end
|
56
60
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
+
- 2
|
8
9
|
- 0
|
9
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- John Barnette
|
@@ -14,37 +15,25 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-05-11 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: gemcutter
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 4
|
30
|
-
- 1
|
31
|
-
version: 0.4.1
|
32
|
-
type: :development
|
33
|
-
version_requirements: *id001
|
34
21
|
- !ruby/object:Gem::Dependency
|
35
22
|
name: hoe
|
36
23
|
prerelease: false
|
37
|
-
requirement: &
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
38
26
|
requirements:
|
39
27
|
- - ">="
|
40
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
41
30
|
segments:
|
42
31
|
- 2
|
43
|
-
-
|
32
|
+
- 6
|
44
33
|
- 0
|
45
|
-
version: 2.
|
34
|
+
version: 2.6.0
|
46
35
|
type: :development
|
47
|
-
version_requirements: *
|
36
|
+
version_requirements: *id001
|
48
37
|
description: |-
|
49
38
|
A stupid simple wrapper for environment variables.
|
50
39
|
|
@@ -80,23 +69,27 @@ rdoc_options:
|
|
80
69
|
require_paths:
|
81
70
|
- lib
|
82
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
83
73
|
requirements:
|
84
74
|
- - ">="
|
85
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
86
77
|
segments:
|
87
78
|
- 0
|
88
79
|
version: "0"
|
89
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
90
82
|
requirements:
|
91
83
|
- - ">="
|
92
84
|
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
93
86
|
segments:
|
94
87
|
- 0
|
95
88
|
version: "0"
|
96
89
|
requirements: []
|
97
90
|
|
98
91
|
rubyforge_project: configlet
|
99
|
-
rubygems_version: 1.3.
|
92
|
+
rubygems_version: 1.3.7.pre.1
|
100
93
|
signing_key:
|
101
94
|
specification_version: 3
|
102
95
|
summary: A stupid simple wrapper for environment variables
|