Class: IBLinterRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/iblinter/iblinter.rb

Instance Method Summary collapse

Constructor Details

#initialize(binary_path) ⇒ IBLinterRunner

Returns a new instance of IBLinterRunner.



4
5
6
# File 'lib/iblinter/iblinter.rb', line 4

def initialize(binary_path)
  @binary_path = binary_path
end

Instance Method Details

#arguments(options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/iblinter/iblinter.rb', line 25

def arguments(options)
  options.
    reject { |_key, value| value.nil? }.
    map { |key, value| value.kind_of?(TrueClass) ? [key, ""] : [key, value] }.
    # map booleans arguments equal false
    map { |key, value| value.kind_of?(FalseClass) ? ["no-#{key}", ""] : [key, value] }.
    # replace underscore by hyphen
    map { |key, value| [key.to_s.tr("_", "-"), value] }.
    # prepend "--" into the argument
    map { |key, value| ["--#{key}", value] }.
    # reduce everything into a single string
    reduce("") { |args, option| "#{args} #{option[0]} #{option[1]}" }.
    # strip leading spaces
    strip
end

#lint(path, options) ⇒ Object



12
13
14
15
16
# File 'lib/iblinter/iblinter.rb', line 12

def lint(path, options)
  command = lint_command(options)
  Dir.chdir path
  JSON.parse(run(command))
end

#lint_command(options) ⇒ Object



18
19
20
21
# File 'lib/iblinter/iblinter.rb', line 18

def lint_command(options)
  abs_binary_path = @binary_path.nil? ? "iblinter" : File.absolute_path(@binary_path)
  "#{abs_binary_path} lint #{arguments(options.merge(reporter: 'json'))}"
end

#run(command) ⇒ Object



8
9
10
# File 'lib/iblinter/iblinter.rb', line 8

def run(command)
  `#{command}`
end