Module: CacheDebugging::Utils
- Defined in:
- lib/cache_debugging/utils.rb
Class Method Summary collapse
-
.deep_flatten(array_or_hash) ⇒ Object
recursively flatten complex array/hash objects.
- .object_partial_path(object) ⇒ Object
-
.publish_notification(name, extra = {}) ⇒ Object
wrapper for ActiveSupport::Notification publish.
Class Method Details
.deep_flatten(array_or_hash) ⇒ Object
recursively flatten complex array/hash objects
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cache_debugging/utils.rb', line 5 def self.deep_flatten(array_or_hash) case array_or_hash when Array array_or_hash.map do |value| if value.is_a?(Hash) || value.is_a?(Array) deep_flatten(value) else value end end.flatten when Hash deep_flatten(array_or_hash.keys + array_or_hash.values) end end |
.object_partial_path(object) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/cache_debugging/utils.rb', line 31 def self.object_partial_path(object) partial = begin object.to_partial_path rescue object.class.model_name.partial_path end partial.split("/").tap{|parts| parts.last.gsub!(/^_?/, "_")}.join("/") end |
.publish_notification(name, extra = {}) ⇒ Object
wrapper for ActiveSupport::Notification publish
21 22 23 24 25 26 27 28 29 |
# File 'lib/cache_debugging/utils.rb', line 21 def self.publish_notification(name, extra = {}) ActiveSupport::Notifications.publish( name, Time.now, # not a block, so fake the start time Time.now, # not a block, so fake the finish time SecureRandom.hex(10), # generate a unique id extra ) end |