module DeployInfo::Util

> Utility Methods

Public Instance Methods

parse_json_config(file = nil, symbolize = true) click to toggle source

> Define JSON Parser

# File lib/deploy-info/util.rb, line 24
def parse_json_config(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/deploy-info/util.rb, line 45
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/deploy-info/util.rb, line 50
def serialize_csv(csv)
  # => Serialize a CSV String into an Array
  return unless csv && csv.is_a?(String)
  csv.split(',')
end
serialize_revisions(branches, tags) click to toggle source
# File lib/deploy-info/util.rb, line 56
def serialize_revisions(branches, tags)
  # => Serialize Branches/Tags into JSON Array
  # => Branches = String, Tags = Key/Value
  branches = branches.map(&:name).sort_by(&:downcase)
  tags = tags.map(&:name).sort_by(&:downcase).reverse.map { |tag| { name: "Tag: #{tag}", value: tag } }
  JSON.pretty_generate(branches + tags)
end
write_json_config(file, object) click to toggle source

> Define JSON Writer

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