module Jerakia::Util
Public Class Methods
autoload(path, mod)
click to toggle source
# File lib/jerakia/util.rb, line 4 def autoload(path, mod) Jerakia.log.debug "autoloading #{path} #{mod}" require "jerakia/#{path}/#{mod}" end
dig(data, dig_path)
click to toggle source
# File lib/jerakia/util.rb, line 9 def dig(data, dig_path) key = dig_path.shift if dig_path.empty? if data.has_key?(key) return data[key] else return :not_found end else return :not_found unless data[key].is_a?(Hash) return dig(data[key], dig_path) end end
walk(data) { |target| ... }
click to toggle source
# File lib/jerakia/util.rb, line 23 def walk(data) if data.is_a?(Hash) walk_hash(data) do |target| yield target end elsif data.is_a?(Array) walk_array(data) do |target| yield target end else yield data end end
walk_array(data) { |x| ... }
click to toggle source
# File lib/jerakia/util.rb, line 51 def walk_array(data) data.map! do |element| if element.is_a?(Hash) walk_hash(element) { |x| yield x } elsif element.is_a?(Array) walk_array(element) { |x| yield x } else yield element end element end end
walk_hash(data) { |x| ... }
click to toggle source
# File lib/jerakia/util.rb, line 37 def walk_hash(data) data.each_with_object({}) do |(_k, v), h| if v.is_a?(Hash) walk_hash(v) { |x| yield x } elsif v.is_a?(Array) walk_array(v) { |x| yield x } else yield v end h end data end