lib/looksist/hashed.rb in looksist-0.1.5 vs lib/looksist/hashed.rb in looksist-0.1.6
- old
+ new
@@ -19,11 +19,12 @@
define_method("#{after}_with_inject") do |*args|
hash = send("#{after}_without_inject".to_sym, *args)
self.class.instance_variable_get(:@rules)[after].each do |opts|
if opts[:at].is_a? String
hash = JsonPath.for(hash.with_indifferent_access).gsub!(opts[:at]) do |i|
- i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts)
+ i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts) unless i.empty?
+ i
end.to_hash.deep_symbolize_keys
else
inject_attributes_at(hash[opts[:at]], opts)
end
end
@@ -39,10 +40,10 @@
end
private
def inject_attributes_at(hash_offset, opts)
- return nil unless hash_offset
+ return hash_offset if hash_offset.nil? or hash_offset.empty?
keys = hash_offset[opts[:using]]
entity_name = __entity__(opts[:using])
values = Looksist.redis_service.send("#{entity_name}_for", keys)
hash_offset[opts[:populate]] = values
hash_offset