Class: Borneo::Mock::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/borneo/mock/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name, version) ⇒ Service

Returns a new instance of Service.



5
6
7
8
9
10
11
# File 'lib/borneo/mock/service.rb', line 5

def initialize(client, name, version)
  @client = client
  @name = name
  @version = version
  @methods = {}
  @response_data = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



30
31
32
# File 'lib/borneo/mock/service.rb', line 30

def method_missing(method_name)
  @methods[method_name] ||= Borneo::Mock::Service.new(@client, @name, @version)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/borneo/mock/service.rb', line 3

def client
  @client
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/borneo/mock/service.rb', line 3

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/borneo/mock/service.rb', line 3

def version
  @version
end

Instance Method Details

#mock_response(components) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/borneo/mock/service.rb', line 17

def mock_response(components)
  if components.count == 0
    @response_data
  else
    next_proxy = @methods[components[0]]
    unless next_proxy.nil?
      next_proxy.mock_response(components.drop(1))
    else
      raise "Request not stubbed for #{components}"
    end
  end
end

#to_return(result) ⇒ Object



13
14
15
# File 'lib/borneo/mock/service.rb', line 13

def to_return(result)
  @response_data = result
end