# version_info.rb

# The version file gets generated by codeship at build time.
# See the file `build-version.sh` for info on the format.

def get_version_info
  version_file = Rails.root.join('lib', 'version.json')

  File.exist?(version_file) ? read_version_file(version_file) : development_version_info
end

def read_version_file(file)
  ret_val = JSON.parse(File.read(file))
rescue JSON::ParserError => e
  Rails.logger.error e
  ret_val = {}
ensure
  ret_val
end

def development_version_info
  {
      'version' => 'development',
      'build_date' => Time.now.strftime("%a %b %d %H:%M:%S %Z %Y"),
      'build_commit' => 'N/A'
  }
end

VERSION_INFO = get_version_info.freeze
