Module: Restool::Service::OperationDefiner

Included in:
RestoolService
Defined in:
lib/restool/service/operation_definer.rb

Instance Method Summary collapse

Instance Method Details

#define_operations(service_config, method_make_request, method_make_request_with_uri_params) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/restool/service/operation_definer.rb', line 7

def define_operations(service_config, method_make_request, method_make_request_with_uri_params)
  service_config.operations.each do |operation|
    if operation.uri_params != []
      define_request_method_with_uri_params(operation, method_make_request_with_uri_params)
    else
      define_request_method(operation, method_make_request)
    end
  end
end

#define_request_method(operation, method_make_request) ⇒ Object



23
24
25
26
27
# File 'lib/restool/service/operation_definer.rb', line 23

def define_request_method(operation, method_make_request)
  define_singleton_method(operation.name) do |*params|
    method_make_request.call(operation, params[0], params[1])
  end
end

#define_request_method_with_uri_params(operation, method_make_request_with_uri_params) ⇒ Object



17
18
19
20
21
# File 'lib/restool/service/operation_definer.rb', line 17

def define_request_method_with_uri_params(operation, method_make_request_with_uri_params)
  define_singleton_method(operation.name) do |uri_params_values, *params|
    method_make_request_with_uri_params.call(operation, uri_params_values, params[0], params[1])
  end
end