module AjaxTest

Constants

VERSION

Public Instance Methods

create_rake_file() click to toggle source
# File lib/ajax_test.rb, line 62
def create_rake_file
  AjaxTest::Generators::AjaxTestGenerator.new.create_rake_file
end
fetch_and_cache_remote_configs() click to toggle source
# File lib/ajax_test.rb, line 18
def fetch_and_cache_remote_configs
  get_api_token_from_app_configs
  fetch_remote_configs if @token.present?
end
fetch_remote_configs() click to toggle source
# File lib/ajax_test.rb, line 28
def fetch_remote_configs
  uri = URI.parse("#{HOST_URL}/keys")
  http = Net::HTTP.new(uri.host, uri.port)
  # http.use_ssl = true
  # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Get.new(uri.request_uri)
  request.add_field(CUSTOM_HEADER, @token)
  @response = http.request(request)
  set_config_vars_from_remote_configs
end
get_api_token_from_app_configs() click to toggle source
# File lib/ajax_test.rb, line 23
def get_api_token_from_app_configs
  @app_configs = YAML::load_file(File.join(Rails.root, 'config', 'application.yml')) || {}
  @token = @app_configs[API_KEY_NAME] || (@app_configs[Rails.env] || {})[API_KEY_NAME]
end
key_already_set?(key) click to toggle source
# File lib/ajax_test.rb, line 58
def key_already_set?(key)
  ENV.key?(key) || @app_configs.include?(key) || (@app_configs[Rails.env] || {}).include?(key)
end
set_config_vars_from_remote_configs() click to toggle source
# File lib/ajax_test.rb, line 39
def set_config_vars_from_remote_configs
  remote_configs = JSON.parse(@response.body) rescue {}
  conflux_yml = File.open(File.join(Rails.root, 'config', 'conflux.yml'), 'w+')
  conflux_yml.write("\n#{YAML_HEADER}\n\n")

  remote_configs.each { |key, value|
    if key_already_set?(key)
      line = "# #{key}: \"#{value}\"  #Overwritten\n"
    else
      line = "#{key}: \"#{value}\"\n"
      ENV[key] = value
    end

    conflux_yml.write(line)
  }

  conflux_yml.close
end
start(*args) click to toggle source
# File lib/ajax_test.rb, line 66
def start(*args)
  puts 'Conflux Ready'
end