module NewRelicManagement::Util
> Utility Methods¶ ↑
Public Instance Methods
cachier(label, time = 30, &block)
click to toggle source
> Cache Return of a Function¶ ↑
# File lib/newrelic-management/util.rb, line 24 def cachier(label, time = 30, &block) var = "@_cachier_#{label}" cache = instance_variable_get(var) || {} return cache['data'] if cache['timestamp'] && Time.now <= cache['timestamp'] + time cache['timestamp'] = Time.now cache['data'] = block.yield instance_variable_set(var, cache) cache['data'] end
cachier!(var = nil)
click to toggle source
> Clear Cache¶ ↑
# File lib/newrelic-management/util.rb, line 35 def cachier!(var = nil) if var && instance_variable_get("@#{var}") # => Clear the Single Variable remove_instance_variable("@#{var}") else # => Clear the Whole Damned Cache instance_variables.each { |x| remove_instance_variable(x) } end end
common_array(ary)
click to toggle source
> Return Common Elements of an Array¶ ↑
# File lib/newrelic-management/util.rb, line 90 def common_array(ary) # rubocop: disable AbcSize return ary unless ary.is_a? Array count = ary.count return ary if count.zero? return ary.flatten.uniq if count == 1 common = ary[0] & ary[1] return common if count == 2 (count - 2).times { |x| common &= ary[x + 2] } if count > 2 common end
filestring(file, size = 8192)
click to toggle source
parse_json(file = nil, symbolize = true)
click to toggle source
serialize(response)
click to toggle source
serialize_csv(csv)
click to toggle source
# File lib/newrelic-management/util.rb, line 83 def serialize_csv(csv) # => Serialize a CSV String into an Array return unless csv && csv.is_a?(String) csv.split(',') end