Class: Querly::Preprocessor

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

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ext:, command:) ⇒ Preprocessor

Returns a new instance of Preprocessor.



16
17
18
19
# File 'lib/querly/preprocessor.rb', line 16

def initialize(ext:, command:)
  @ext = ext
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



14
15
16
# File 'lib/querly/preprocessor.rb', line 14

def command
  @command
end

#extObject (readonly)

Returns the value of attribute ext.



13
14
15
# File 'lib/querly/preprocessor.rb', line 13

def ext
  @ext
end

Instance Method Details

#run!(path) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/querly/preprocessor.rb', line 21

def run!(path)
  stdout_read, stdout_write = IO.pipe

  output = ""

  reader = Thread.new do
    while (line = stdout_read.gets)
      output << line
    end
  end

  succeeded = system(command, in: path.to_s, out: stdout_write)
  stdout_write.close

  reader.join

  raise Error.new(status: $?, command: command) unless succeeded

  output
end