Class: Restool::Mock::Service

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

Instance Method Summary collapse

Constructor Details

#initialize(service_config, operation_responses) ⇒ Service

Returns a new instance of Service.



15
16
17
18
# File 'lib/restool/mock/restool.rb', line 15

def initialize(service_config, operation_responses)
  @service_config = service_config
  @operation_responses = operation_responses
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



20
21
22
23
24
25
26
27
28
# File 'lib/restool/mock/restool.rb', line 20

def method_missing(method, *args, &block)
  if @service_config.operations.map(&:name).include?(method)
    operation_response      = @operation_responses[method]
    response_representation = @service_config.operation.response
    representations         = @service_config.representations

    Restool::Traversal::Converter.convert(operation_response, response_representation, representations)
  end
end