module Blocks::HashWithCaller
Attributes
callers[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/blocks/utilities/hash_with_caller.rb, line 7 def initialize(*args) self.callers = {} super end
Public Instance Methods
initialize_copy(original)
click to toggle source
Calls superclass method
# File lib/blocks/utilities/hash_with_caller.rb, line 12 def initialize_copy(original) super self.callers = original.callers.clone end
reverse_merge!(*args)
click to toggle source
TODO: fix and test this implementation def to_s
description = [] description << "{" description << map do |key, value| value_display = case value when Symbol ":#{value}" when String "\"#{value}\"" when Proc "Proc" else value end "\"#{key}\" => #{value_display}, # [#{callers[key]}]" end.join(",\n") description << "}" description.join("\n")
end
Calls superclass method
# File lib/blocks/utilities/hash_with_caller.rb, line 41 def reverse_merge!(*args) options = args.extract_options! caller_id = args.first.to_s.presence || "" if !options.is_a?(HashWithCaller) && Blocks.lookup_caller_location caller_location = caller.detect do |c| !c.include?("/lib/blocks") && !c.include?("/lib/ruby") && !c.include?("patch") end.try(:split, ":in").try(:[], 0) caller_id += " from #{caller_location}" if caller_location end options.each do |key, value| current_value = self[key] if options.is_a?(HashWithCaller) setter = options.callers[key] else setter = "set by #{caller_id}" end if !self.key?(key) callers[key] = setter elsif current_value.is_a?(Hash) && value.is_a?(Hash) # self[key] = value.deep_merge(current_value) callers[key] = "#{callers[key]}, #{setter}" end end super options end