Sha256: 6f1c146b7a05ee3aaba20c40ffbf3a4fe17a98878fd197c931a2ad10872d813c

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 Bytes

Contents

require 'rake'
require 'stringio'

module Rails
  module Sh
    module Rake
      class << self
        def init
          $stdout = StringIO.new
          ::Rake.application = ::Rake::Application.new
          ::Rake.application.init
          ::Rake.application.load_rakefile
          ::Rake.application[:environment].invoke
        ensure
          $stdout = STDOUT
        end

        def invoke(line)
          name, *args = line.split(/\s+/)
          pid = fork do
            args.each do |arg|
              env, value = arg.split('=')
              next unless env && !env.empty? && value && !value.empty?
              ENV[env] = value
            end
            ::Rake.application[name].invoke
          end
          Process.waitpid(pid)
        end

        def task_names
          ::Rake.application.tasks.map{|t| t.name}
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails-sh-1.2.5 lib/rails/sh/rake.rb
rails-sh-1.2.4 lib/rails/sh/rake.rb
rails-sh-1.2.3 lib/rails/sh/rake.rb