Class: Sassconf::SassExecutor

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/sassconf/sass_executor.rb

Constant Summary collapse

SASS_PROCESS =
'sass %s %s %s'
SASS_VALUE_ARGUMENT =
'--%s=%s '
SASS_ARGUMENT =
'--%s %s '

Instance Method Summary collapse

Methods included from Logging

activate, configure_logger_for, #logger, logger_for

Constructor Details

#initialize(sass_input, sass_output) ⇒ SassExecutor

Returns a new instance of SassExecutor.



14
15
16
17
# File 'lib/sassconf/sass_executor.rb', line 14

def initialize(sass_input, sass_output)
  @sass_input = sass_input
  @sass_output = sass_output
end

Instance Method Details

#create_all_argument_strings(argument_value_hash, argument_hash) ⇒ Object



27
28
29
# File 'lib/sassconf/sass_executor.rb', line 27

def create_all_argument_strings(argument_value_hash, argument_hash)
  create_argument_with_value_string(argument_value_hash).concat(' ').concat(create_argument_string(argument_hash))
end

#create_argument_string(argument_hash) ⇒ Object



23
24
25
# File 'lib/sassconf/sass_executor.rb', line 23

def create_argument_string(argument_hash)
  create_string(SASS_ARGUMENT, argument_hash)
end

#create_argument_with_value_string(argument_hash) ⇒ Object



19
20
21
# File 'lib/sassconf/sass_executor.rb', line 19

def create_argument_with_value_string(argument_hash)
  create_string(SASS_VALUE_ARGUMENT, argument_hash)
end

#detach_and_killObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sassconf/sass_executor.rb', line 38

def detach_and_kill
  unless @pid.nil?
    logger.info("Detach Sass process: #{@pid}")
    Process.detach(@pid)
    out, status = if Util.windows? then
                    logger.info("Find child processes on MS-DOS")
                    Open3.capture2("wmic process where (ParentProcessId=#{@pid.to_s}) get ProcessId")
                  else
                    logger.info("Find child processes on UNIX")
                    Open3.capture2('ps', 'h', '--ppid', @pid.to_s, '-o', 'pid')
                  end
    logger.info("Kill process: #{@pid}")
    Process.kill('KILL', @pid)
    out.each_line do |elem|
      pid = elem.to_i;
      unless pid == 0
        Process.kill('KILL', pid)
        logger.info("Killed child process: #{pid}")
      end
    end
  end
end

#execute(argument_string) ⇒ Object



31
32
33
34
35
36
# File 'lib/sassconf/sass_executor.rb', line 31

def execute(argument_string)
  Util.pre_check((argument_string.is_string? and argument_string.is_not_nil_or_empty?), 'Argument string is no string, nil or empty.')

  @pid = spawn(SASS_PROCESS % [argument_string, @sass_input, @sass_output])
  logger.info("Spawn Sass process: #{@pid}")
end

#waitObject



61
62
63
64
# File 'lib/sassconf/sass_executor.rb', line 61

def wait
  logger.info("Wait for Sass process: #{@pid}")
  Process.wait(@pid) unless @pid.nil?
end