Sha256: 825c24a4ab8e8bb0b9ed087d22cf3d670119bcc0dba8fa2262631c5812f4a43f

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

require_relative '../feature/ruby/merge_gem'
require_relative '../feature/ruby/merge_gemfile'
require_relative '../feature/ruby/merge_exec'

module IronWorkerNG
  module Code
    class Ruby < IronWorkerNG::Code::Base
      include IronWorkerNG::Feature::Ruby::MergeGem::InstanceMethods
      include IronWorkerNG::Feature::Ruby::MergeGemfile::InstanceMethods
      include IronWorkerNG::Feature::Ruby::MergeExec::InstanceMethods

      def create_runner(zip)
        gempath_code_array = []
      
        @features.each do |f|
          if f.respond_to?(:code_for_gempath)
            gempath_code_array << f.send(:code_for_gempath)
          end
        end

        gempath_code = gempath_code_array.join("\n")

        zip.get_output_stream(runner) do |runner|
          runner.write <<RUNNER
# iron_worker_ng-#{IronWorkerNG.version}

root = nil
payload_file = nil
task_id = nil

0.upto($*.length - 2) do |i|
  root = $*[i + 1] if $*[i] == '-d'
  payload_file = $*[i + 1] if $*[i] == '-payload'
  task_id = $*[i + 1] if $*[i] == '-id'
end

Dir.chdir(root)

#{gempath_code}
$:.unshift("\#{root}")

require 'json'

@iron_task_id = task_id

@payload = File.read(payload_file)

@params = {}
begin
  @params = JSON.parse(@payload)
rescue
end

keys = @params.keys
keys.each do |key|
  @params[key.to_sym] = @params[key]
end

def payload
  @payload
end

def params
  @params
end

def iron_task_id
  @iron_task_id
end

require '#{File.basename(@exec.path)}'

exec_class = nil

begin
  exec_class = Kernel.const_get('#{@exec.klass}')
rescue
end

unless exec_class.nil?
  exec_inst = exec_class.new

  params.keys.each do |param|
    if param.class == String
      if exec_inst.respond_to?(param + '=')
        exec_inst.send(param + '=', params[param])
      end
    end
  end

  exec_inst.run
end
RUNNER
        end
      end

      def runtime
        'ruby'
      end

      def runner
        '__runner__.rb'
      end
    end
  end
end

IronWorkerNG::Code::Base.register_type(:name => 'ruby', :klass => IronWorkerNG::Code::Ruby)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
iron_worker_ng-0.3.8 lib/iron_worker_ng/code/ruby.rb
iron_worker_ng-0.3.7 lib/iron_worker_ng/code/ruby.rb
iron_worker_ng-0.3.6 lib/iron_worker_ng/code/ruby.rb