Sha256: f8ff2ab95f489c0a946a07f9aba2114e99f25d9cd1676a847eb59735dfe63039

Contents?: true

Size: 801 Bytes

Versions: 11

Compression:

Stored size: 801 Bytes

Contents

require 'v8'

class Class
  def native_impl(lib)
    class << self
      def new(*args)
        js = {
          'Gherkin::Formatter::JSONFormatter' => 'js/lib/gherkin/formatter/json_formatter.js'
        }[self.name]
        if(js)
          Proxy.new(js, *args)
        else
          super(*args)
        end
      end
    end
  end

  class Proxy
    def initialize(js, *args)
      cxt = V8::Context.new
      cxt['module'] = {}

      # Mimic Node.js / Firebug console.log
      cxt['console'] = STDOUT
      def STDOUT.log(*a)
        puts sprintf(*a)
      end

      cxt.load(js)
      @js_obj = cxt['module']['exports'].new(*args)
    end

    def method_missing(name, *args)
      a = args.map{|a| a.respond_to?(:to_hash) ? a.to_hash : a}
      @js_obj.__send__(name, *a)
    end
  end
end

Version data entries

11 entries across 9 versions & 4 rubygems

Version Path
candlepin-api-0.4.0 bundle/ruby/1.8/gems/gherkin-2.11.1/lib/gherkin/native/therubyracer.rb
candlepin-api-0.4.0 bundle/ruby/gems/gherkin-2.11.1/lib/gherkin/native/therubyracer.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/gherkin-2.11.1/lib/gherkin/native/therubyracer.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/gherkin-2.11.1/lib/gherkin/native/therubyracer.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/gherkin-2.11.1/lib/gherkin/native/therubyracer.rb
bryanl-gherkin-2.11.1.1-java lib/gherkin/native/therubyracer.rb
bryanl-gherkin-2.11.1.1 lib/gherkin/native/therubyracer.rb
gherkin-2.11.1 lib/gherkin/native/therubyracer.rb
gherkin-2.11.1-x86-mswin32 lib/gherkin/native/therubyracer.rb
gherkin-2.11.1-x86-mingw32 lib/gherkin/native/therubyracer.rb
gherkin-2.11.1-java lib/gherkin/native/therubyracer.rb