module NewRelicRMQPlugin::Util

> Utility Methods

Public Instance Methods

filestring(file, size = 8192) click to toggle source

> Check if a string is an existing file, and return it's content

# File lib/newrelic-rmq-plugin/util.rb, line 42
def filestring(file, size = 8192)
  return unless file
  return file unless file.is_a?(String) && File.file?(file) && File.size(file) <= size
  File.read(file)
end
parse_json(file = nil, symbolize = true) click to toggle source

> Define JSON Parser

# File lib/newrelic-rmq-plugin/util.rb, line 24
def parse_json(file = nil, symbolize = true)
  return unless file && ::File.exist?(file.to_s)
  begin
    ::JSON.parse(::File.read(file.to_s), symbolize_names: symbolize)
  rescue JSON::ParserError
    return
  end
end
serialize(response) click to toggle source

> Serialization <= #

# File lib/newrelic-rmq-plugin/util.rb, line 52
def serialize(response)
  # => Serialize Object into JSON Array
  JSON.pretty_generate(response.map(&:name).sort_by(&:downcase))
end
serialize_csv(csv) click to toggle source
# File lib/newrelic-rmq-plugin/util.rb, line 57
def serialize_csv(csv)
  # => Serialize a CSV String into an Array
  return unless csv && csv.is_a?(String)
  csv.split(',')
end
write_json(file, object) click to toggle source

> Define JSON Writer

# File lib/newrelic-rmq-plugin/util.rb, line 34
def write_json(file, object)
  return unless file && object
  begin
    File.open(file, 'w') { |f| f.write(JSON.pretty_generate(object)) }
  end
end