Skip to content

Commit

Permalink
Merge pull request #26 from mbklein/add_missing_structurize_method
Browse files Browse the repository at this point in the history
Add missing structurize method.
  • Loading branch information
jrochkind committed Oct 26, 2015
2 parents 0c65af4 + 889c2d4 commit d4e0274
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/confstruct/hash_with_struct_access.rb
Expand Up @@ -122,6 +122,14 @@ def lookup! key_path, fallback = nil
end
return val
end

def self.structurize hash
result = hash
if result.is_a?(Hash) and not result.is_a?(HashWithStructAccess)
result = HashWithStructAccess.new(result)
end
result
end

def method_missing sym, *args, &block
name = sym.to_s.chomp('=').to_sym
Expand All @@ -134,7 +142,7 @@ def method_missing sym, *args, &block
raise TypeError, "Cannot #add! to a #{self[name].class}"
end
if args.length > 0
local_args = args.collect { |a| structurize! a }
local_args = args.collect { |a| self.class.structurize a }
result = self[name].push *local_args
elsif block_given?
result = HashWithStructAccess.new
Expand Down

0 comments on commit d4e0274

Please sign in to comment.