class FakeApi::FakeApiData

Attributes

responses[R]
routes[R]

Public Class Methods

instance() click to toggle source
# File lib/fake_api/data.rb, line 6
def FakeApiData.instance
  @@instance ||= FakeApiData.new
end
new() click to toggle source
# File lib/fake_api/data.rb, line 10
def initialize
  @responses = {}
  @routes    = {}
end

Public Instance Methods

build(something)
Alias for: object
create(something)
Alias for: object
create_list(something, amount) click to toggle source
# File lib/fake_api/data.rb, line 52
def create_list(something, amount)
  result = []
  amount.times { result << response_or_value(something) }
  result
end
delete(path) click to toggle source
# File lib/fake_api/data.rb, line 42
def delete(path)
  route("DELETE", route: path)
end
factory(name, &block) click to toggle source
# File lib/fake_api/data.rb, line 15
def factory(name, &block)
  response = Factory.new(name: name, value: block)
  @responses[name] = response
end
get(path) click to toggle source
# File lib/fake_api/data.rb, line 26
def get(path)
  route("GET", route: path)
end
object(something) click to toggle source
# File lib/fake_api/data.rb, line 46
def object(something)
  response_or_value(something)
end
Also aliased as: create, build
patch(path) click to toggle source
# File lib/fake_api/data.rb, line 38
def patch(path)
  route("PATCH", route: path)
end
post(path) click to toggle source
# File lib/fake_api/data.rb, line 30
def post(path)
  route("POST", route: path)
end
put(path) click to toggle source
# File lib/fake_api/data.rb, line 34
def put(path)
  route("PUT", route: path)
end
response_or_value(e) click to toggle source
# File lib/fake_api/data.rb, line 58
def response_or_value(e)
  if e.is_a?(Symbol)
    if response = FakeApiData.instance.responses[e]
      response.value.call
    else
      nil
    end
  else
    e
  end
end
route(request_method, route:, &block) click to toggle source
# File lib/fake_api/data.rb, line 20
def route(request_method, route:, &block)
  e = Route.new(route: route)
  @routes[request_method.upcase] ||= {}
  @routes[request_method.upcase][route] = e
end