Class: RokuBuilder::RafInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/roku_builder/plugins/raf_inspector.rb

Constant Summary collapse

RAF_INTERFACE_INITIALIZATION_PATTERN =
/roku_ads\(\)/i
LIBRARY_IMPORT_PATTERN =
/\s*library\s*"roku_ads.brs"\s*/i

Instance Method Summary collapse

Constructor Details

#initialize(config:, dir:) ⇒ RafInspector

Returns a new instance of RafInspector.



9
10
11
12
13
14
15
16
17
18
# File 'lib/roku_builder/plugins/raf_inspector.rb', line 9

def initialize(config:, dir:)
  @config = config
  @dir = dir
  @has_raf_interface_initialization = false
  @interface_location = {}
  @has_library_import = false
  @import_location = {}
  @has_manifest_entry = false
  @manifest_location = {path: "manifest"}
end

Instance Method Details

#inspect_line(line:, file:, line_number:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/roku_builder/plugins/raf_inspector.rb', line 20

def inspect_line(line:, file:, line_number:)
  unless @has_raf_interface_initialization
    @has_raf_interface_initialization = !!RAF_INTERFACE_INITIALIZATION_PATTERN.match(line)
    if @has_raf_interface_initialization
      @interface_location = {path: file, line: line_number}
    end
  end
  unless @has_library_import
    @has_library_import = !!LIBRARY_IMPORT_PATTERN.match(line)
    if @has_library_import
      @import_location = {path: file, line: line_number}
    end
  end
end

#inspect_manifest(attributes:, line_numbers:) ⇒ Object



35
36
37
38
39
40
# File 'lib/roku_builder/plugins/raf_inspector.rb', line 35

def inspect_manifest(attributes:, line_numbers:)
  if attributes[:bs_libs_required] and attributes[:bs_libs_required].downcase == "roku_ads_lib"
    @has_manifest_entry = true
    @manifest_location[:line] = line_numbers[:bs_libs_required]
  end
end

#run(inspector_config) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/roku_builder/plugins/raf_inspector.rb', line 42

def run(inspector_config)
  @warnings = []
  @inspector_config = inspector_config
  if @has_raf_interface_initialization and !@has_library_import
    add_warning(warning: :rafConstructorPresentImportMissing, location: @interface_location)
  end
  if @has_raf_interface_initialization and !@has_manifest_entry
    add_warning(warning: :rafConstructorPresentManifestMissing, location: @interface_location)
  end
  if !@has_raf_interface_initialization and @has_manifest_entry
    add_warning(warning: :rafConstructorMissingManifestPresent, location: @manifest_location)
  end
  if @has_manifest_entry and !@has_library_import
    add_warning(warning: :rafManifestPresentImportMissing, location: @manifest_location)
  end
  if !@has_raf_interface_initialization and @has_library_import
    add_warning(warning: :rafConstructorMissingImportPresent, location: @import_location)
  end
  if @has_raf_interface_initialization and @has_library_import and @has_manifest_entry
    add_warning(warning: :rafProperIntegration, location: @import_location)
  end
  @warnings
end