Sha256: 1aacb27cc6505d1eaaa3c13eed70b4314ad937de77262c4a40ca2011f9e05e87

Contents?: true

Size: 844 Bytes

Versions: 29

Compression:

Stored size: 844 Bytes

Contents

module Gherkin
  module Formatter
    class Hashable
      def to_hash
        ivars = instance_variables
        # When tests are runn with therubyracer (JavaScript), an extra field might
        # exist - added by Ref::WeakReference
        # https://github.com/bdurand/ref/blob/master/lib/ref/weak_reference/pure_ruby.rb
        # Remove it - we don't want it in the JSON.
        ivars.delete(:@__weak_backreferences__)
        ivars.inject({}) do |hash, ivar|
          value = instance_variable_get(ivar)
          value = value.to_hash if value.respond_to?(:to_hash)
          if Array === value
            value = value.map do |e|
              e.respond_to?(:to_hash) ? e.to_hash : e
            end
          end
          hash[ivar[1..-1]] = value unless [[], nil].index(value)
          hash
        end
      end
    end
  end
end

Version data entries

29 entries across 27 versions & 3 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/gherkin-2.12.2/lib/gherkin/formatter/hashable.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/gherkin-2.12.2/lib/gherkin/formatter/hashable.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/gherkin-2.12.2/lib/gherkin/formatter/hashable.rb
gherkin-2.12.2 lib/gherkin/formatter/hashable.rb
gherkin-2.12.2-x86-mswin32 lib/gherkin/formatter/hashable.rb
gherkin-2.12.2-x86-mingw32 lib/gherkin/formatter/hashable.rb
gherkin-2.12.2-java lib/gherkin/formatter/hashable.rb
gherkin-2.12.1 lib/gherkin/formatter/hashable.rb
gherkin-2.12.1-x86-mswin32 lib/gherkin/formatter/hashable.rb
gherkin-2.12.1-x86-mingw32 lib/gherkin/formatter/hashable.rb
gherkin-2.12.1-java lib/gherkin/formatter/hashable.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/gherkin-2.11.6/lib/gherkin/formatter/hashable.rb
gherkin-2.12.0 lib/gherkin/formatter/hashable.rb
gherkin-2.12.0-x86-mingw32 lib/gherkin/formatter/hashable.rb
gherkin-2.12.0-x86-mswin32 lib/gherkin/formatter/hashable.rb
gherkin-2.12.0-java lib/gherkin/formatter/hashable.rb
gherkin-2.11.8 lib/gherkin/formatter/hashable.rb
gherkin-2.11.8-x86-mswin32 lib/gherkin/formatter/hashable.rb
gherkin-2.11.8-x86-mingw32 lib/gherkin/formatter/hashable.rb
gherkin-2.11.8-java lib/gherkin/formatter/hashable.rb