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



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

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

#compiled_libxslt_versionObject



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

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

#engineObject



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

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

#jruby?Boolean

Returns:

  • (Boolean)


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

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

#libxml2?Boolean

Returns:

  • (Boolean)


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

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

#libxml2_has_iconv?Boolean

Returns:

  • (Boolean)


52
53
54
# 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

Returns:

  • (Boolean)


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

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

#libxml2_using_packaged?Boolean

Returns:

  • (Boolean)


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

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

#libxml2_using_system?Boolean

Returns:

  • (Boolean)


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

def libxml2_using_system?
  libxml2? && !libxml2_using_packaged?
end

#libxslt_has_datetime?Boolean

Returns:

  • (Boolean)


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

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

#loaded_libxml_versionObject



26
27
28
29
30
31
# 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_versionObject



37
38
39
40
41
42
# 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_minorObject



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

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

#to_hashObject



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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# 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 like nokogumbo to build with the following in their extconf.rb:
        #
        #    append_cflags(Nokogiri::VERSION_INFO["nokogiri"]["cppflags"])
        #    append_ldflags(Nokogiri::VERSION_INFO["nokogiri"]["ldflags"])
        #
        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}"

          if windows?
            # on windows, nokogumbo needs to 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
        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

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

#to_markdownObject



179
180
181
182
183
# File 'lib/nokogiri/version/info.rb', line 179

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

#warningsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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

#windows?Boolean

Returns:

  • (Boolean)


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

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