Class: Vastlint::Library

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/vastlint/library.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resolve_pathObject

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vastlint/library.rb', line 47

def resolve_path
  candidates = [ENV["VASTLINT_LIB_PATH"], vendored_path, *development_paths].compact
  match = candidates.find { |candidate| File.file?(candidate) }
  return match if match

  raise LibraryError, <<~MESSAGE.strip
    unable to find libvastlint for #{platform_label}
    looked in:
    #{candidates.map { |candidate| "  - #{candidate}" }.join("\n")}
    set VASTLINT_LIB_PATH or vendor a release library under lib/vastlint/native
  MESSAGE
end

Instance Method Details

#pathObject



42
43
44
# File 'lib/vastlint/library.rb', line 42

def path
  self.class.resolve_path
end

#validate(xml, wrapper_depth:, max_wrapper_depth:, rule_overrides:) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vastlint/library.rb', line 13

def validate(xml, wrapper_depth:, max_wrapper_depth:, rule_overrides:)
  raw_result = if default_call?(wrapper_depth, max_wrapper_depth, rule_overrides)
    api.vastlint_validate(xml, xml.bytesize)
  else
    api.vastlint_validate_with_options(
      xml,
      xml.bytesize,
      wrapper_depth,
      max_wrapper_depth,
      serialize_rule_overrides(rule_overrides)
    )
  end

  raise LibraryError, "vastlint returned NULL" if null_pointer?(raw_result)

  begin
    json_payload = read_c_string(api.vastlint_result_json(raw_result))
    raise LibraryError, "vastlint_result_json returned NULL" if json_payload.nil? || json_payload.empty?

    json_payload
  ensure
    api.vastlint_result_free(raw_result) unless null_pointer?(raw_result)
  end
end

#versionObject



38
39
40
# File 'lib/vastlint/library.rb', line 38

def version
  read_c_string(api.vastlint_version()) || raise(LibraryError, "vastlint_version returned NULL")
end