Class: LintTrap::Command
- Inherits:
-
Object
- Object
- LintTrap::Command
- Defined in:
- lib/lint_trap/command.rb
Overview
Wraps the execution of linter commands
Instance Attribute Summary collapse
-
#binary ⇒ Object
readonly
Returns the value of attribute binary.
Instance Method Summary collapse
- #command(container = LintTrap::Container::Fake.new) ⇒ Object (also: #to_s)
- #files(container = LintTrap::Container::Fake.new) ⇒ Object
- #flags ⇒ Object
-
#initialize(binary, flags, files) ⇒ Command
constructor
A new instance of Command.
- #run(container) ⇒ Object
Constructor Details
#initialize(binary, flags, files) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 |
# File 'lib/lint_trap/command.rb', line 9 def initialize(binary, flags, files) @binary = binary @flags = flags @files = files end |
Instance Attribute Details
#binary ⇒ Object (readonly)
Returns the value of attribute binary.
7 8 9 |
# File 'lib/lint_trap/command.rb', line 7 def binary @binary end |
Instance Method Details
#command(container = LintTrap::Container::Fake.new) ⇒ Object Also known as: to_s
25 26 27 |
# File 'lib/lint_trap/command.rb', line 25 def command(container = LintTrap::Container::Fake.new) container.wrap("#{binary} #{flags} #{files(container)}") end |
#files(container = LintTrap::Container::Fake.new) ⇒ Object
30 31 32 |
# File 'lib/lint_trap/command.rb', line 30 def files(container = LintTrap::Container::Fake.new) Shellwords.join(@files.map{|file| container.container_path(file)}) end |
#flags ⇒ Object
34 35 36 |
# File 'lib/lint_trap/command.rb', line 34 def flags @flags.join(' ') end |
#run(container) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/lint_trap/command.rb', line 15 def run(container) Bundler.with_clean_env do Open3.popen2e(command(container)) do |_, stdout, thread| yield stdout if block_given? thread.value.success? end end end |