class Hyperion

Constants

Config

Attributes

route[R]

Public Class Methods

configure() { |config| ... } click to toggle source
# File lib/hyperion/hyperion.rb, line 45
def self.configure
  yield(config)
end
fake(base_uri, &routes) click to toggle source

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
new(route) click to toggle source

@private

# File lib/hyperion/hyperion.rb, line 28
def initialize(route)
  @route = route
end
request(route, body: nil, additional_headers: {}, timeout: 0, &block) click to toggle source

@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
reset() click to toggle source

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
teardown_cached_servers() click to toggle source

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

config() click to toggle source
# File lib/hyperion/hyperion.rb, line 53
def self.config
  @config ||= Config.new('indigobio-ascent')
end
normalized_base(uri) click to toggle source
# File lib/hyperion_test/fake.rb, line 54
def normalized_base(uri)
  HyperionUri.new(uri).base
end
server_pool() click to toggle source
# File lib/hyperion_test/fake.rb, line 48
def server_pool
  @server_pool ||= ServerPool.new
end
servers() click to toggle source
# File lib/hyperion_test/fake.rb, line 44
def servers
  @servers ||= Hash.new { |hash, key| hash[key] = server_pool.check_out }
end
transform_uri(uri) click to toggle source

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

request(body, additional_headers, timeout, &dispatch) click to toggle source

@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

build_headers(additional_headers) click to toggle source
# File lib/hyperion/hyperion.rb, line 57
def build_headers(additional_headers)
  route_headers(route).merge(additional_headers)
end
hyperion_result_for(typho_result, dispatch) click to toggle source
# 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
transform_uri(uri) click to toggle source
# File lib/hyperion/hyperion.rb, line 73
def transform_uri(uri)
  Hyperion.send(:transform_uri, uri)
end