Sha256: 22b9698310cf9af8ef5b2c3fdd39cd9185a5fa5d8d0c0851d38a12649f581f65

Contents?: true

Size: 1.09 KB

Versions: 80

Compression:

Stored size: 1.09 KB

Contents

class Class
  # Causes a Java class to be instantiated instead of the Ruby class when 
  # running on JRuby. This is used to test both pure Java and pure Ruby classes 
  # from the same Ruby based test suite. The Java Class must have a package name
  # that corresponds with the Ruby class.
  def java_impl(jar)
    if defined?(JRUBY_VERSION)
      require jar
      class << self
        def javaify(arg)
          if Array === arg
            arg.map{|a| javaify(a)}
          else
            case(arg)
            when Regexp
              java.util.regex.Pattern.compile(arg.source)
            else
              arg
            end
          end
        end

        def new(*args)
          java_class.new(*javaify(args))
        end

        def ===(object)
          super || object.java_kind_of?(java_class)
        end

        def java_class
          names = self.name.split('::')
          package = Java
          names[0..-2].each do |module_name|
            package = package.__send__(module_name.downcase)
          end

          package.__send__(names[-1])
        end
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
gherkin-1.0.29 lib/gherkin/java_impl.rb
gherkin-1.0.29-i386-mswin32 lib/gherkin/java_impl.rb
gherkin-1.0.29-i386-mingw32 lib/gherkin/java_impl.rb
gherkin-1.0.29-java lib/gherkin/java_impl.rb
gherkin-1.0.28 lib/gherkin/java_impl.rb
gherkin-1.0.28-i386-mswin32 lib/gherkin/java_impl.rb
gherkin-1.0.28-i386-mingw32 lib/gherkin/java_impl.rb
gherkin-1.0.28-java lib/gherkin/java_impl.rb
gherkin-1.0.27 lib/gherkin/java_impl.rb
gherkin-1.0.27-i386-mswin32 lib/gherkin/java_impl.rb
gherkin-1.0.27-i386-mingw32 lib/gherkin/java_impl.rb
gherkin-1.0.27-java lib/gherkin/java_impl.rb
gherkin-1.0.26 lib/gherkin/java_impl.rb
gherkin-1.0.26-i386-mswin32 lib/gherkin/java_impl.rb
gherkin-1.0.26-i386-mingw32 lib/gherkin/java_impl.rb
gherkin-1.0.26-java lib/gherkin/java_impl.rb
gherkin-1.0.25 lib/gherkin/java_impl.rb
gherkin-1.0.25-i386-mswin32 lib/gherkin/java_impl.rb
gherkin-1.0.25-i386-mingw32 lib/gherkin/java_impl.rb
gherkin-1.0.25-java lib/gherkin/java_impl.rb