Class: MemoriClient::Swagger::GetModuleAndMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/memori_client/swagger/get_module_and_method.rb

Instance Method Summary collapse

Constructor Details

#initialize(namespace, method, path, endpoint_data) ⇒ GetModuleAndMethod

Returns a new instance of GetModuleAndMethod.



4
5
6
7
8
9
# File 'lib/memori_client/swagger/get_module_and_method.rb', line 4

def initialize(namespace, method, path, endpoint_data)
  @endpoint_data = endpoint_data
  @namespace = namespace
  @method = method
  @path = path
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/memori_client/swagger/get_module_and_method.rb', line 11

def call
  # Load using gem path as root
  gem_path = Gem.loaded_specs['memori-client'].full_gem_path
  # Not sure if this is visible after gem release.
  overrides_path = File.join(gem_path, "#{@namespace}_overrides.jsonc")
  if File.exist?(overrides_path)
    overrides = JSON.parse(File.open(overrides_path).read)
  else
    raise "No overrides found for #{@namespace}"
  end
  # overrides = JSON.parse(File.open("#{@namespace}_overrides.jsonc").read)
  key = [@method, @path].join(' ')
  if overrides.key?(key)
    # puts "THERE IS AN OVERRIDE FOR #{key}. Operation id is #{@endpoint_data['operationId']}"
    value = overrides[key]
    return value.split('#')
  end

  if @endpoint_data.key?('operationId')
    version = @path.split('/').find { |t| t =~ /v\d+/ }
    controller, action = @endpoint_data['operationId'].split('-')
    mod = [
      'MemoriClient',
      @namespace.titleize,
      version.upcase,
      controller.singularize
    ].join('::')

    return [mod, action.underscore]
  end
end