Class: IBLinterRunner
- Inherits:
-
Object
- Object
- IBLinterRunner
- Defined in:
- lib/iblinter/iblinter.rb
Instance Method Summary collapse
-
#arguments(options) ⇒ Object
Parse options into shell arguments.
-
#initialize(binary_path) ⇒ IBLinterRunner
constructor
A new instance of IBLinterRunner.
- #lint(path, options) ⇒ Object
- #lint_command(options) ⇒ Object
- #run(command) ⇒ Object
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
Parse options into shell arguments. Reference github.com/ashfurrow/danger-ruby-swiftlint/blob/0af6d5aff38dc666352ea3750266fb7630d88bdd/ext/swiftlint/swiftlint.rb#L38
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/iblinter/iblinter.rb', line 25 def arguments() . 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, ) command = lint_command() 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() abs_binary_path = @binary_path.nil? ? "iblinter" : File.absolute_path(@binary_path) "#{abs_binary_path} lint #{arguments(.merge(reporter: 'json'))}" end |
#run(command) ⇒ Object
8 9 10 |
# File 'lib/iblinter/iblinter.rb', line 8 def run(command) `#{command}` end |