summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorErol Fornoles <erol.fornoles@gmail.com>2014-12-29 09:56:11 +0800
committerErol Fornoles <erol.fornoles@gmail.com>2014-12-30 01:49:26 +0800
commit725c3ceacb2482f26e1832baaae99d8899ea3d1e (patch)
tree7c22de2f02d1ac133ddd210437ba43b9bed845a8 /lib
parenta18864fe1d079daf3eda5cf14a168ef6abd6403c (diff)
downloadhashie-725c3ceacb2482f26e1832baaae99d8899ea3d1e.tar.gz
Fix handling of default proc values in Mash
Diffstat (limited to 'lib')
-rw-r--r--lib/hashie/mash.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index 6d30a94..5d9e847 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -61,13 +61,13 @@ module Hashie
SUFFIXES_PARSER = /(.*?)([#{ALLOWED_SUFFIXES.join}]?)$/
def self.load(path, options = {})
- @_mashes ||= new do |h, file_path|
- fail ArgumentError, "The following file doesn't exist: #{file_path}" unless File.file?(file_path)
+ @_mashes ||= new
- parser = options.fetch(:parser) { Hashie::Extensions::Parsers::YamlErbParser }
- h[file_path] = new(parser.perform(file_path)).freeze
- end
- @_mashes[path]
+ return @_mashes[path] if @_mashes.key?(path)
+ fail ArgumentError, "The following file doesn't exist: #{path}" unless File.file?(path)
+
+ parser = options.fetch(:parser) { Hashie::Extensions::Parsers::YamlErbParser }
+ @_mashes[path] = new(parser.perform(path)).freeze
end
def to_module(mash_method_name = :settings)
@@ -106,6 +106,7 @@ module Hashie
# Retrieves an attribute set in the Mash. Will convert
# any key passed in to a string before retrieving.
def custom_reader(key)
+ default_proc.call(self, key) if default_proc && !key?(key)
value = regular_reader(convert_key(key))
yield value if block_given?
value
@@ -245,7 +246,7 @@ module Hashie
when '_'
underbang_reader(name)
else
- default(method_name)
+ self[method_name]
end
end