123456789_123456789_123456789_123456789_123456789_

Class: Nokogiri::VersionInfo

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Singleton
Inherits: Object
Defined in: lib/nokogiri/version/info.rb

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#jruby?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 10

def jruby?
  ::JRUBY_VERSION if ::RUBY_PLATFORM == "java"
end

#libxml2?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 48

def libxml2?
  defined?(Nokogiri::LIBXML_COMPILED_VERSION)
end

#libxml2_has_iconv?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 52

def libxml2_has_iconv?
  defined?(Nokogiri::LIBXML_ICONV_ENABLED) && Nokogiri::LIBXML_ICONV_ENABLED
end

#libxml2_precompiled?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 68

def libxml2_precompiled?
  libxml2_using_packaged? && Nokogiri::PRECOMPILED_LIBRARIES
end

#libxml2_using_packaged?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 60

def libxml2_using_packaged?
  libxml2? && Nokogiri::PACKAGED_LIBRARIES
end

#libxml2_using_system?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 64

def libxml2_using_system?
  libxml2? && !libxml2_using_packaged?
end

#libxslt_has_datetime?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 56

def libxslt_has_datetime?
  defined?(Nokogiri::LIBXSLT_DATETIME_ENABLED) && Nokogiri::LIBXSLT_DATETIME_ENABLED
end

#windows?Boolean (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 14

def windows?
  ::RUBY_PLATFORM =~ /mingw|mswin/
end

Instance Method Details

#compiled_libxml_version

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 33

def compiled_libxml_version
  Gem::Version.new(Nokogiri::LIBXML_COMPILED_VERSION)
end

#compiled_libxslt_version

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 44

def compiled_libxslt_version
  Gem::Version.new(Nokogiri::LIBXSLT_COMPILED_VERSION)
end

#engine

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 22

def engine
  defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : "mri"
end

#loaded_libxml_version

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 26

def loaded_libxml_version
  Gem::Version.new(Nokogiri::LIBXML_LOADED_VERSION
    .scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first
    .collect(&:to_i)
    .join("."))
end

#loaded_libxslt_version

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 37

def loaded_libxslt_version
  Gem::Version.new(Nokogiri::LIBXSLT_LOADED_VERSION
    .scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first
    .collect(&:to_i)
    .join("."))
end

#ruby_minor

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 18

def ruby_minor
  Gem::Version.new(::RUBY_VERSION).segments[0..1].join(".")
end

#to_hash

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 88

def to_hash
  header_directory = File.expand_path(File.join(File.dirname(__FILE__), "../../../ext/nokogiri"))

  {}.tap do |vi|
    vi["warnings"] = []
    vi["nokogiri"] = {}.tap do |nokogiri|
      nokogiri["version"] = Nokogiri::VERSION

      unless jruby?
        #  enable gems to build against Nokogiri with the following in their extconf.rb:
        #
        #    append_cflags(Nokogiri::VERSION_INFO["nokogiri"]["cppflags"])
        #    append_ldflags(Nokogiri::VERSION_INFO["nokogiri"]["ldflags"])
        #
        #  though, this won't work on all platform and versions of Ruby, and won't be supported
        #  forever, see https://github.com/sparklemotion/nokogiri/discussions/2746 for context.
        #
        cppflags = ["-I#{header_directory.shellescape}"]
        ldflags = []

        if libxml2_using_packaged?
          cppflags << "-I#{File.join(header_directory, "include").shellescape}"
          cppflags << "-I#{File.join(header_directory, "include/libxml2").shellescape}"
        end

        if windows?
          # on windows, third party libraries that wish to link against nokogiri
          # should link against nokogiri.so to resolve symbols. see #2167
          lib_directory = File.expand_path(File.join(File.dirname(__FILE__), "../#{ruby_minor}"))
          unless File.exist?(lib_directory)
            lib_directory = File.expand_path(File.join(File.dirname(__FILE__), ".."))
          end
          ldflags << "-L#{lib_directory.shellescape}"
          ldflags << "-l:nokogiri.so"
        end

        nokogiri["cppflags"] = cppflags
        nokogiri["ldflags"] = ldflags
      end
    end
    vi["ruby"] = {}.tap do |ruby|
      ruby["version"] = ::RUBY_VERSION
      ruby["platform"] = ::RUBY_PLATFORM
      ruby["gem_platform"] = ::Gem::Platform.local.to_s
      ruby["description"] = ::RUBY_DESCRIPTION
      ruby["engine"] = engine
      ruby["jruby"] = jruby? if jruby?
    end

    if libxml2?
      vi["libxml"] = {}.tap do |libxml|
        if libxml2_using_packaged?
          libxml["source"] = "packaged"
          libxml["precompiled"] = libxml2_precompiled?
          libxml["patches"] = Nokogiri::LIBXML2_PATCHES
        else
          libxml["source"] = "system"
        end
        libxml["memory_management"] = Nokogiri::LIBXML_MEMORY_MANAGEMENT
        libxml["iconv_enabled"] = libxml2_has_iconv?
        libxml["compiled"] = compiled_libxml_version.to_s
        libxml["loaded"] = loaded_libxml_version.to_s
      end

      vi["libxslt"] = {}.tap do |libxslt|
        if libxml2_using_packaged?
          libxslt["source"] = "packaged"
          libxslt["precompiled"] = libxml2_precompiled?
          libxslt["patches"] = Nokogiri::LIBXSLT_PATCHES
        else
          libxslt["source"] = "system"
        end
        libxslt["datetime_enabled"] = libxslt_has_datetime?
        libxslt["compiled"] = compiled_libxslt_version.to_s
        libxslt["loaded"] = loaded_libxslt_version.to_s
      end

      vi["warnings"] = warnings
    end

    if defined?(Nokogiri::OTHER_LIBRARY_VERSIONS)
      # see extconf for how this string is assembled: "lib1name:lib1version,lib2name:lib2version"
      vi["other_libraries"] = Hash[*Nokogiri::OTHER_LIBRARY_VERSIONS.split(/[,:]/)]
    elsif jruby?
      vi["other_libraries"] = {}.tap do |ol|
        Nokogiri::JAR_DEPENDENCIES.each do |k, v|
          ol[k] = v
        end
      end
    end
  end
end

#to_markdown

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 181

def to_markdown
  require "yaml"
  "# Nokogiri (#{Nokogiri::VERSION})\n" +
    YAML.dump(to_hash).each_line.map { |line| "    #{line}" }.join
end

#warnings

[ GitHub ]

  
# File 'lib/nokogiri/version/info.rb', line 72

def warnings
  warnings = []

  if libxml2?
    if compiled_libxml_version != loaded_libxml_version
      warnings << "Nokogiri was built against libxml version #{compiled_libxml_version}, but has dynamically loaded #{loaded_libxml_version}"
    end

    if compiled_libxslt_version != loaded_libxslt_version
      warnings << "Nokogiri was built against libxslt version #{compiled_libxslt_version}, but has dynamically loaded #{loaded_libxslt_version}"
    end
  end

  warnings
end