Sha256: ad3d74c617a61452989a55c532ddf9c4e757ec6bac5fccfae5f0caa8aaf87159

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

require 'json'

module Feast
  # API class represents a set of APIs
  # This class is also a rack app but this might change in the future
  class API
    # `@results` variable stores results for all paths
    def initialize
      @results = {}
    end

    # Accepts GET request
    #
    # @param route [String]
    def get(route)
      @results[route] = yield
      self
    end

    # rubocop:disable Style/StringHashKeys
    # rack app convention
    #
    # @param env [Rack::ENV]
    def call(env)
      path_info = env['PATH_INFO']
      result = @results[path_info] || ''
      [200, { 'ContentType' => 'application/json' }, [result]]
    end
    # rubocop:enable Style/StringHashKeys
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
feast-0.0.1 lib/feast/api.rb