configlet 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +14 -0
- data/lib/configlet.rb +9 -12
- data/test/test_configlet.rb +12 -1
- metadata +6 -10
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -45,6 +45,20 @@ resolved the first time its value is grabbed.
|
|
45
45
|
Configlet is a module, so +include+ or +extend+ it wherever you
|
46
46
|
want. It extends itself for your convenience.
|
47
47
|
|
48
|
+
== Transformation
|
49
|
+
|
50
|
+
Want something other than a string? You can munge any value:
|
51
|
+
|
52
|
+
default :url => "http://example.org"
|
53
|
+
munge(:url) { |v| URI.parse v }
|
54
|
+
Configlet[:url] # => #<URI::HTTP:0xdeadbeef URL:http://example.org>
|
55
|
+
|
56
|
+
In fact, there's a shortcut just for URLs. I haven't added any others
|
57
|
+
'cause I haven't needed to care:
|
58
|
+
|
59
|
+
url :url => "http://example.org"
|
60
|
+
Configlet[:url] # => #<URI::HTTP:0xcafebabe URL:http://example.org>
|
61
|
+
|
48
62
|
== Installation
|
49
63
|
|
50
64
|
$ gem install configlet
|
data/lib/configlet.rb
CHANGED
@@ -13,7 +13,7 @@ module Configlet
|
|
13
13
|
|
14
14
|
# Duh.
|
15
15
|
|
16
|
-
VERSION = "
|
16
|
+
VERSION = "2.0.0"
|
17
17
|
|
18
18
|
I = lambda { |v| v } #:nodoc:
|
19
19
|
|
@@ -88,11 +88,6 @@ module Configlet
|
|
88
88
|
instance_eval(&block)
|
89
89
|
end
|
90
90
|
|
91
|
-
def for *args, &block #:nodoc:
|
92
|
-
warn "Configlet.for is deprecated, and will be removed in 2.0."
|
93
|
-
config(*args, &block)
|
94
|
-
end
|
95
|
-
|
96
91
|
# Mess with a value when it's retrieved. Useful for turning untyped
|
97
92
|
# environment strings into numbers, booleans, enums, or class
|
98
93
|
# instances. Here's how to munge a boolean:
|
@@ -111,14 +106,16 @@ module Configlet
|
|
111
106
|
@mungers ||= Hash.new { |h, k| I }
|
112
107
|
end
|
113
108
|
|
114
|
-
#
|
109
|
+
# Behaves exactly like +default+, but additionally installs a munger
|
110
|
+
# for each key that calls <tt>URI.parse</tt>.
|
115
111
|
|
116
|
-
def
|
117
|
-
|
118
|
-
|
112
|
+
def url args, &block
|
113
|
+
default args, &block
|
114
|
+
require "uri"
|
119
115
|
|
120
|
-
|
121
|
-
|
116
|
+
(args.keys rescue [args]).each do |key|
|
117
|
+
munge(key) { |v| URI.parse v }
|
118
|
+
end
|
122
119
|
end
|
123
120
|
|
124
121
|
extend self
|
data/test/test_configlet.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require "minitest/autorun"
|
2
1
|
require "configlet"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "uri"
|
3
4
|
|
4
5
|
class TestConfiglet < MiniTest::Unit::TestCase
|
5
6
|
class Stub
|
@@ -74,4 +75,14 @@ class TestConfiglet < MiniTest::Unit::TestCase
|
|
74
75
|
@cfg[:thud] = "zap"
|
75
76
|
assert_equal "zap", ENV["POW_THUD"]
|
76
77
|
end
|
78
|
+
|
79
|
+
def test_url
|
80
|
+
@cfg.url :example => "http://example.org"
|
81
|
+
assert_equal URI.parse("http://example.org"), @cfg[:example]
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_url_block
|
85
|
+
@cfg.url(:example) { "http://example.org" }
|
86
|
+
assert_equal URI.parse("http://example.org"), @cfg[:example]
|
87
|
+
end
|
77
88
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
|
-
-
|
8
|
-
- 3
|
6
|
+
- 2
|
9
7
|
- 0
|
10
|
-
|
8
|
+
- 0
|
9
|
+
version: 2.0.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- John Barnette
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-09-28 00:00:00 -07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +25,11 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
28
|
segments:
|
31
29
|
- 2
|
32
30
|
- 6
|
33
|
-
-
|
34
|
-
version: 2.6.
|
31
|
+
- 2
|
32
|
+
version: 2.6.2
|
35
33
|
type: :development
|
36
34
|
version_requirements: *id001
|
37
35
|
description: |-
|
@@ -73,7 +71,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
71
|
requirements:
|
74
72
|
- - ">="
|
75
73
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
74
|
segments:
|
78
75
|
- 0
|
79
76
|
version: "0"
|
@@ -82,7 +79,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
79
|
requirements:
|
83
80
|
- - ">="
|
84
81
|
- !ruby/object:Gem::Version
|
85
|
-
hash: 3
|
86
82
|
segments:
|
87
83
|
- 0
|
88
84
|
version: "0"
|