Class: Wavefront::Internals

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront-sdk/internals.rb

Overview

Methods to inspect the SDK itselr.

Constant Summary collapse

API_REGEX =
%r{^\s+ # (GET|POST|PUT|DELETE|PATCH) /}

Instance Method Summary collapse

Instance Method Details

#clean_paths(paths) ⇒ Object

rubocop:enable Metrics/AbcSize



41
42
43
# File 'lib/wavefront-sdk/internals.rb', line 41

def clean_paths(paths)
  paths.flatten.compact.map { |s| s.strip.sub(/^# /, '') }
end

#missing_api_pathsObject



61
62
63
64
65
66
67
# File 'lib/wavefront-sdk/internals.rb', line 61

def missing_api_paths
  # We don't have an explicit method for the many search paths: they're
  # all bundled together under a generic Wavefront::Search.
  (remote_api_paths - supported_api_paths).reject do |_method, path|
    path.start_with?('/api/v2/search/')
  end
end

#remote_api_paths(spec = swagger_spec) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/wavefront-sdk/internals.rb', line 53

def remote_api_paths(spec = swagger_spec)
  paths = JSON.parse(spec)['paths'].map do |path, data|
    data.keys.map { |verb| [verb.upcase, path].join(' ') }
  end

  paths_struct(paths.flatten)
end

#sdk_filesArray[Pathname]

Returns SDK API files.

Returns:

  • (Array[Pathname])

    SDK API files



15
16
17
18
19
# File 'lib/wavefront-sdk/internals.rb', line 15

def sdk_files
  Pathname.glob("#{__dir__}/**/*")
          .select { |f| f.file? && f.extname == '.rb' }
          .reject { |f| f == Pathname.new(__FILE__) }
end

#search_paths(paths, files) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/wavefront-sdk/internals.rb', line 45

def search_paths(paths, files)
  search_paths = paths.select { |_v, x| x.include?('/search/') }

  search_paths.each_with_object([]) do |(verb, path), ret|
    files.each { |f| ret << [verb, path.sub('{entity}', api_word(f))] }
  end
end

#supported_api_pathsArray[String]

Depends on the code being commented correctly, so not 100% bulletproof.

rubocop:disable Metrics/AbcSize

Returns:

  • (Array[String])

    list of all the remote API paths the SDK covers.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wavefront-sdk/internals.rb', line 25

def supported_api_paths
  mix = { acl: [], tag: [], user: [] }
  searches = []

  paths = sdk_files.map do |f|
    lines = File.readlines(f)
    searches << f if lines.grep('CoreApi')
    mix.each_key { |m| mix[m] << f if lines.grep(%r{"api_mixins/#{m}"}) }
    lines.grep(API_REGEX)
  end

  clean = paths_struct(clean_paths(paths))
  clean + mixin_paths(clean, mix) + search_paths(clean, searches)
end