Class: RackDoubles::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_doubles/client.rb

Defined Under Namespace

Classes: Server

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, http_client = RestClient) ⇒ Client

Returns a new instance of Client.



14
15
16
17
# File 'lib/rack_doubles/client.rb', line 14

def initialize(server, http_client = RestClient) 
  @server = server
  @http_client = http_client
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



8
9
10
# File 'lib/rack_doubles/client.rb', line 8

def server
  @server
end

Class Method Details

.create(arg, http_client) ⇒ Object



10
11
12
# File 'lib/rack_doubles/client.rb', line 10

def self.create arg, http_client
  new(Server.new(extract_args(arg)), http_client)
end

Instance Method Details

#delete(resource) ⇒ Object



23
24
25
# File 'lib/rack_doubles/client.rb', line 23

def delete resource
  @http_client.delete url_for(resource)
end

#delete_allObject



27
28
29
# File 'lib/rack_doubles/client.rb', line 27

def delete_all
  @http_client.delete url_for('/')
end

#stub(resource) ⇒ Object



19
20
21
# File 'lib/rack_doubles/client.rb', line 19

def stub resource
  @stub = Stub.new url_for(resource), @http_client
end

#url_for(path) ⇒ Object



31
32
33
# File 'lib/rack_doubles/client.rb', line 31

def url_for path
  "#{server.url}/#{path.gsub(/^\/+/, '')}"
end