configlet 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 1.1.0 / 2010-02-25
2
+
3
+ * Add Configlet#for, a sugary block form.
4
+ * Squash warnings for 1.8.6.
5
+
1
6
  === 1.0.0 / 2010-01-04
2
7
 
3
8
  * Birthday!
@@ -28,8 +28,16 @@ and use it instead.
28
28
  Configlet[:finished] # => false
29
29
  Configlet[:token] # => "default-token"
30
30
 
31
- It's a module, so +include+ or +extend+ it wherever you want. It
32
- extends itself for your convenience.
31
+ There's also a block form, which is nice if you're setting a lot of
32
+ defaults:
33
+
34
+ Configlet.for :thunk do
35
+ default :token => "default-token"
36
+ default :host => "thunk.local"
37
+ end
38
+
39
+ Configlet is a module, so +include+ or +extend+ it wherever you
40
+ want. It extends itself for your convenience.
33
41
 
34
42
  == Installation
35
43
 
@@ -13,7 +13,7 @@ module Configlet
13
13
 
14
14
  # Duh.
15
15
 
16
- VERSION = "1.0.0"
16
+ VERSION = "1.1.0"
17
17
 
18
18
  I = lambda { |v| v } #:nodoc:
19
19
 
@@ -27,14 +27,14 @@ module Configlet
27
27
  # <tt>defaults["severity"]</tt> if the env var isn't set.
28
28
 
29
29
  def [] key
30
- mungers[key.to_s].call ENV[envify key] || defaults[key.to_s]
30
+ mungers[key.to_s].call ENV[envify(key)] || defaults[key.to_s]
31
31
  end
32
32
 
33
33
  # Set an environment value. +key+ is translated to an unfriendly
34
34
  # environment name as in Configlet#[] above.
35
35
 
36
36
  def []= key, value
37
- ENV[envify key] = value
37
+ ENV[envify(key)] = value
38
38
  end
39
39
 
40
40
  # Set one or more default values. Use "friendly" names, not env
@@ -54,6 +54,19 @@ module Configlet
54
54
  [prefix, key].compact.join("_").tr(".", "_").upcase
55
55
  end
56
56
 
57
+ # Swanky block form. More pleasant to read when setting multiple
58
+ # defaults, e.g.,
59
+ #
60
+ # Configlet.for :myapp do
61
+ # default "email.from" => "noreply@myapp.com"
62
+ # default :host => "myapp.local"
63
+ # end
64
+
65
+ def for prefix, &block
66
+ self.prefix = prefix
67
+ instance_eval(&block)
68
+ end
69
+
57
70
  # Mess with a value when it's retrieved. Useful for turning untyped
58
71
  # environment strings into numbers, booleans, enums, or class
59
72
  # instances. Here's how to munge a boolean:
@@ -18,6 +18,17 @@ class TestConfiglet < MiniTest::Unit::TestCase
18
18
  assert_equal "bar", Configlet["foo"]
19
19
  end
20
20
 
21
+ def test_for
22
+ ENV["PREFIX_FOO"] = "bar"
23
+
24
+ Configlet.for :prefix do
25
+ default :bar => "baz"
26
+ end
27
+
28
+ assert_equal "bar", Configlet[:foo]
29
+ assert_equal "baz", Configlet[:bar]
30
+ end
31
+
21
32
  def test_get
22
33
  ENV["FOO"] = "bar"
23
34
  assert_equal "bar", Configlet[:foo]
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configlet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 0
9
+ version: 1.1.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - John Barnette
@@ -9,29 +14,37 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-09 00:00:00 -08:00
17
+ date: 2010-02-25 00:00:00 -08:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: gemcutter
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
23
- version: 0.2.1
24
- version:
27
+ segments:
28
+ - 0
29
+ - 4
30
+ - 1
31
+ version: 0.4.1
32
+ type: :development
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: hoe
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 5
44
+ - 0
33
45
  version: 2.5.0
34
- version:
46
+ type: :development
47
+ version_requirements: *id002
35
48
  description: |-
36
49
  A stupid simple wrapper for environment variables.
37
50
 
@@ -70,18 +83,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
83
  requirements:
71
84
  - - ">="
72
85
  - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
73
88
  version: "0"
74
- version:
75
89
  required_rubygems_version: !ruby/object:Gem::Requirement
76
90
  requirements:
77
91
  - - ">="
78
92
  - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
79
95
  version: "0"
80
- version:
81
96
  requirements: []
82
97
 
83
98
  rubyforge_project: configlet
84
- rubygems_version: 1.3.5
99
+ rubygems_version: 1.3.6
85
100
  signing_key:
86
101
  specification_version: 3
87
102
  summary: A stupid simple wrapper for environment variables