Module: Neutron

Defined in:
lib/neutron.rb,
lib/neutron/version.rb

Defined Under Namespace

Modules: CC, PkgStatus Classes: ExecutionError, FileList, FilePair, FilePairList, PkgConf, Valac

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.execute(string, **opts) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/neutron.rb', line 65

def self.execute(string, **opts)
  puts "> #{string}"
  stdin, stdout, waiter = *Open3.popen2e(string)
  out = '' 
  while s = stdout.getc
    print s
    out << s
  end
  stdin.close
  stdout.close
  if opts[:must_success] and waiter.value.exitstatus != 0
    raise Neutron::ExecutionError, "Exitcode #{waiter.value.exitstatus} returned!"
  end
  return [out, waiter.value.exitstatus]
end

.files(sources, t_ext) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/neutron.rb', line 43

def self.files(sources, t_ext)
  targets = sources.ext(t_ext)
  pairs = sources.zip(targets)
  pairs = pairs.keep_if do |item|
    source = item[0]
    target = item[1]
    if File.exist? target
      st = File.stat(File.expand_path(source)).mtime
      tt = File.stat(File.expand_path(target)).mtime
      if st > tt
        true
      else
        false
      end
    else
      true
    end
  end
  pairs.map!{|item| Neutron::FilePair.new(item[0], item[1])}
  Neutron::FilePairList.new(pairs)
end