Class: Mimic::FakeHost

Inherits:
Object
  • Object
show all
Defined in:
lib/mimic/fake_host.rb

Defined Under Namespace

Classes: StubbedRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, remote_configuration_path = nil) ⇒ FakeHost

Returns a new instance of FakeHost.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mimic/fake_host.rb', line 8

def initialize(hostname, remote_configuration_path = nil)
  @hostname = hostname
  @stubs = []
  @app = Class.new(Sinatra::Base)
  @remote_configuration_path = remote_configuration_path

  @app.not_found do
    [404, {}, ""]
  end
  
  build_url_map!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



58
59
60
# File 'lib/mimic/fake_host.rb', line 58

def method_missing(method, *args, &block)
  @app.send(method, *args, &block)
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



6
7
8
# File 'lib/mimic/fake_host.rb', line 6

def hostname
  @hostname
end

#url_mapObject (readonly)

Returns the value of attribute url_map.



6
7
8
# File 'lib/mimic/fake_host.rb', line 6

def url_map
  @url_map
end

Instance Method Details

#call(env) ⇒ Object



47
48
49
50
# File 'lib/mimic/fake_host.rb', line 47

def call(env)
  @stubs.each(&:build)
  @app.call(env)
end

#clearObject



52
53
54
# File 'lib/mimic/fake_host.rb', line 52

def clear
  @stubs.clear
end

#delete(path, &block) ⇒ Object



33
34
35
# File 'lib/mimic/fake_host.rb', line 33

def delete(path, &block)
  request("DELETE", path, &block)
end

#get(path, &block) ⇒ Object



21
22
23
# File 'lib/mimic/fake_host.rb', line 21

def get(path, &block)
  request("GET", path, &block)
end

#head(path, &block) ⇒ Object



37
38
39
# File 'lib/mimic/fake_host.rb', line 37

def head(path, &block)
  request("HEAD", path, &block)
end

#import(path) ⇒ Object



41
42
43
44
45
# File 'lib/mimic/fake_host.rb', line 41

def import(path)
  if File.exists?(path)
    instance_eval(File.read(path))
  end
end

#post(path, &block) ⇒ Object



25
26
27
# File 'lib/mimic/fake_host.rb', line 25

def post(path, &block)
  request("POST", path, &block)
end

#put(path, &block) ⇒ Object



29
30
31
# File 'lib/mimic/fake_host.rb', line 29

def put(path, &block)
  request("PUT", path, &block)
end