Class: Nokogiri::VersionInfo

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/nokogiri/version/info.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#compiled_libxml_versionObject


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

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

#compiled_libxslt_versionObject


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

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

#engineObject


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

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

#jruby?Boolean

Returns:

  • (Boolean)

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

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

#libxml2?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/nokogiri/version/info.rb', line 39

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

#libxml2_has_iconv?Boolean

Returns:

  • (Boolean)

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

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

#libxml2_precompiled?Boolean

Returns:

  • (Boolean)

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

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

#libxml2_using_packaged?Boolean

Returns:

  • (Boolean)

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

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

#libxml2_using_system?Boolean

Returns:

  • (Boolean)

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

def libxml2_using_system?
  libxml2? && !libxml2_using_packaged?
end

#loaded_libxml_versionObject


17
18
19
20
21
22
# File 'lib/nokogiri/version/info.rb', line 17

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_versionObject


28
29
30
31
32
33
# File 'lib/nokogiri/version/info.rb', line 28

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

#to_hashObject


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/nokogiri/version/info.rb', line 75

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?
        cppflags = ["-I#{header_directory.shellescape}"]
        if libxml2_using_packaged?
          cppflags << "-I#{File.join(header_directory, "include").shellescape}"
          cppflags << "-I#{File.join(header_directory, "include/libxml2").shellescape}"
        end
        nokogiri["cppflags"] = cppflags
      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

          # this is for nokogumbo and shouldn't be forever
          libxml["libxml2_path"] = header_directory
        else
          libxml["source"] = "system"
        end
        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["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|
        ol["xerces"] = Nokogiri::XERCES_VERSION
        ol["nekohtml"] = Nokogiri::NEKO_VERSION
      end
    end
  end
end

#to_markdownObject


144
145
146
147
148
149
150
151
152
# File 'lib/nokogiri/version/info.rb', line 144

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

#warningsObject


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nokogiri/version/info.rb', line 59

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