lib/dense/methods.rb in dense-1.1.3 vs lib/dense/methods.rb in dense-1.1.4

- old
+ new

@@ -58,10 +58,32 @@ .reverse pa.narrow(r) end + def force_set(o, path, value) + + Dense::Path.make(path) + .gather(o) + .each { |hit| + if hit[0] == false + n = hit[4].first + fail_miss_error(path, hit) \ + if n.nil? && ! key_matches_collection?(hit[3], hit[2]) + hit[2][hit[3]] = + if n.is_a?(String) + {} + else + [] + end + return force_set(o, path, value) + end + hit[2][hit[3]] = value } + + value + end + def insert(o, path, value) Dense::Path.make(path) .gather(o) .each { |hit| @@ -89,9 +111,15 @@ Dense::Path.make(path).gather(o) end protected + + def key_matches_collection?(k, c) + + (c.is_a?(Hash) && k.is_a?(String)) || + (c.is_a?(Array) && k.is_a?(Integer)) + end module DenseError attr_accessor :full_path, :miss