Class: FakeServer::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_server/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, log_file = nil) ⇒ Server

Returns a new instance of Server.



7
8
9
10
# File 'lib/fake_server/server.rb', line 7

def initialize(host, log_file=nil)
  @remote_api = RemoteAPI.new(host)
  @logger = Logger.new(log_file || STDOUT)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/fake_server/server.rb', line 12

def logger
  @logger
end

#remote_apiObject (readonly)

Returns the value of attribute remote_api.



12
13
14
# File 'lib/fake_server/server.rb', line 12

def remote_api
  @remote_api
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fake_server/server.rb', line 14

def call(env)
  url = env["REQUEST_URI"]
  method = env["REQUEST_METHOD"]

  logger.info("#{method} #{url}")
  if method == "GET"
    name = cassette_name(url)
    logger.info("using cassette #{name}")
    VCR.use_cassette(name) { remote_api.request(method, url) }
  else
    remote_api.request(method, url)
  end

end