Sha256: 6e967664f2cf4397809929c2efb0a826ec609c2e85cecf9c7fb80d8e7557cf33

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'yaml'

module Jeka

  class Implementation
    attr_reader :folder
    attr_reader :info
    
    def initialize(folder)
      if folder[-1] == "/"
        @folder = folder
      else
        @folder = "#{folder}/"
      end
      _load
    end
    
    def _load
      @info = YAML::load(File.open(File.join(@folder, '_info.yaml'))) if File.exists?(File.join(@folder, '_info.yaml'))
      @run = YAML::load(File.open(File.join(@folder, '_run.yaml'))) if File.exists?(File.join(@folder, '_run.yaml'))
      @build = YAML::load(File.open(File.join(@folder, '_build.yaml'))) if File.exists?(File.join(@folder, '_build.yaml'))
    end
    
    def run(output, input)
      out = []
      arg = nil
      arg = File.join(@folder, @run['arguments']) if @run['arguments']
      command = @run['command']
      new_command = @run['command'].sub("$", @folder)
      while not new_command == command
        command = new_command
        new_command = new_command.sub("$", @folder)
      end
      if output
        system("#{command} #{arg if arg} #{"< #{input}" if input}")
      else
        IO.popen("#{command} #{arg if arg} #{"< #{input}" if input}") do |io|
          out = io.readlines
        end
      end
      return out.join("\n")
    end
    
    def build
      if @build
        command = @build["command"]
        new_command = @build["command"].sub("$", @folder)
        while not new_command == command
          command = new_command
          new_command = new_command.sub("$", @folder)
        end
        system(new_command)
      end
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jeka-0.1.0 lib/jeka/implementation.rb