Module: AjaxTest
- Extended by:
- AjaxTest
- Included in:
- AjaxTest
- Defined in:
- lib/ajax_test.rb,
lib/ajax_test/railtie.rb,
lib/ajax_test/version.rb,
lib/generators/ajax_test/ajax_test_generator.rb
Defined Under Namespace
Modules: Generators
Classes: Railtie
Constant Summary
collapse
- VERSION =
'1.1.9'
Instance Method Summary
collapse
Instance Method Details
#create_rake_file ⇒ Object
#fetch_and_cache_remote_configs ⇒ Object
18
19
20
21
|
# 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 ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# 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)
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 ⇒ Object
23
24
25
26
|
# 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) ⇒ Boolean
58
59
60
|
# 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 ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# 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) ⇒ Object
66
67
68
|
# File 'lib/ajax_test.rb', line 66
def start(*args)
puts 'Conflux Ready'
end
|