Permalink
Browse files

Make config prefix optional, default to class name (ish).

  • Loading branch information...
1 parent 658135e commit 89f887c63af2f2c561b53c2d3530bdcd008fc5a1 @jbarnette committed Dec 15, 2010
Showing with 16 additions and 3 deletions.
  1. +9 −3 lib/configlet.rb
  2. +7 −0 test/test_configlet.rb
View
@@ -82,10 +82,16 @@ def envify key #:nodoc:
# default "email.from" => "noreply@myapp.com"
# default :host => "myapp.local"
# end
+ #
+ # If +prefix+ isn't specified, a downcased version of the current
+ # class' name will be used.
+
+ def config prefix = nil, &block
+ self.prefix = prefix ||
+ (Class === self ? self : self.class).
+ name.split("::").last.downcase.to_sym
- def config prefix, &block
- self.prefix = prefix
- instance_eval(&block)
+ instance_eval(&block) if block_given?
end
# Mess with a value when it's retrieved. Useful for turning untyped
View
@@ -27,6 +27,13 @@ def test_config
assert_equal "baz", @cfg[:bar]
end
+ def test_config_auto_prefix
+
+ ENV["STUB_FOO"] = "bar"
+ @cfg.config
+ assert_equal "bar", @cfg[:foo]
+ end
+
def test_default
assert_nil @cfg["foo"]

0 comments on commit 89f887c

Please sign in to comment.