class Hyperion
Constants
- Config
Attributes
Public Class Methods
# File lib/hyperion/hyperion.rb, line 45 def self.configure yield(config) end
Configure routes on the server for the given base_uri
# File lib/hyperion_test/fake.rb, line 18 def fake(base_uri, &routes) base_uri = normalized_base(base_uri) unless @configured hook_reset if can_hook_reset? && !reset_registered? @configured = true end servers[base_uri].configure(&routes) end
@private
# File lib/hyperion/hyperion.rb, line 28 def initialize(route) @route = route end
@param route [RestRoute] @param body [String] the body to send with POST or PUT @param additional_headers [Hash] headers to send in addition to the ones
already determined by the route. Example: +{'User-Agent' => 'Mozilla/5.0'}+
@param timeout [Integer] The limit of the entire request in seconds @yield [result] yields the result if a block is provided @yieldparam [HyperionResult] @return [HyperionResult, Object] If a block is provided, returns the block's
return value; otherwise, returns the result.
# File lib/hyperion/hyperion.rb, line 23 def self.request(route, body: nil, additional_headers: {}, timeout: 0, &block) self.new(route).request(body, additional_headers, timeout, &block) end
Clear routes but don't stop servers. Meant to be called between tests. Starting/stopping servers is relatively slow. They can be reused.
# File lib/hyperion_test/fake.rb, line 29 def reset servers.values.each { |s| server_pool.check_in(s) } servers.clear @configured = false end
Stop all servers. This should only need to be called by tests that use Kim
directly (like kim_spec.rb).
# File lib/hyperion_test/fake.rb, line 37 def teardown_cached_servers reset server_pool.clear end
Private Class Methods
# File lib/hyperion/hyperion.rb, line 53 def self.config @config ||= Config.new('indigobio-ascent') end
# File lib/hyperion_test/fake.rb, line 54 def normalized_base(uri) HyperionUri.new(uri).base end
# File lib/hyperion_test/fake.rb, line 48 def server_pool @server_pool ||= ServerPool.new end
# File lib/hyperion_test/fake.rb, line 44 def servers @servers ||= Hash.new { |hash, key| hash[key] = server_pool.check_out } end
give Hyperion::Test a shot at changing the uri for stubbing purposes
# File lib/hyperion/hyperion.rb, line 78 def self.transform_uri(uri) uri end
Public Instance Methods
@private
# File lib/hyperion/hyperion.rb, line 33 def request(body, additional_headers, timeout, &dispatch) uri = transform_uri(route.uri).to_s with_request_logging(route, uri, route_headers(route)) do typho_result = Typho.request(uri, method: route.method, headers: build_headers(additional_headers), body: write(body, route.payload_descriptor), timeout: timeout) hyperion_result_for(typho_result, dispatch) end end
Private Instance Methods
# File lib/hyperion/hyperion.rb, line 57 def build_headers(additional_headers) route_headers(route).merge(additional_headers) end
# File lib/hyperion/hyperion.rb, line 61 def hyperion_result_for(typho_result, dispatch) result_maker = ResultMaker.new(route) if dispatch # callcc allows control to "jump" back here when the first predicate matches Util.callcc do |cont| dispatch.call(result_maker.make(typho_result, cont)) end else result_maker.make(typho_result) end end
# File lib/hyperion/hyperion.rb, line 73 def transform_uri(uri) Hyperion.send(:transform_uri, uri) end