Class: Nokogiri::VersionInfo

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

Overview

:nodoc:

Constant Summary collapse

@@instance =

FIXME: maybe switch to singleton?

new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject


123
# File 'lib/nokogiri/version.rb', line 123

def self.instance; @@instance; end

Instance Method Details

#compiled_libxml_versionObject


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

def compiled_libxml_version
  Gem::Version.new LIBXML_COMPILED_VERSION
end

#compiled_libxslt_versionObject


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

def compiled_libxslt_version
  Gem::Version.new LIBXSLT_COMPILED_VERSION
end

#engineObject


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

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

#jruby?Boolean

Returns:

  • (Boolean)

7
8
9
# File 'lib/nokogiri/version.rb', line 7

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

#libxml2?Boolean

Returns:

  • (Boolean)

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

def libxml2?
  defined?(LIBXML_COMPILED_VERSION)
end

#libxml2_using_packaged?Boolean

Returns:

  • (Boolean)

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

def libxml2_using_packaged?
  NOKOGIRI_USE_PACKAGED_LIBRARIES
end

#libxml2_using_system?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/nokogiri/version.rb', line 41

def libxml2_using_system?
  !libxml2_using_packaged?
end

#loaded_libxml_versionObject


15
16
17
18
19
20
# File 'lib/nokogiri/version.rb', line 15

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

#loaded_libxslt_versionObject


26
27
28
29
30
31
# File 'lib/nokogiri/version.rb', line 26

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

#to_hashObject


65
66
67
68
69
70
71
72
73
74
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
# File 'lib/nokogiri/version.rb', line 65

def to_hash
  {}.tap do |vi|
    vi["warnings"] = []
    vi["nokogiri"] = Nokogiri::VERSION
    vi["ruby"] = {}.tap do |ruby|
      ruby["version"] = ::RUBY_VERSION
      ruby["platform"] = ::RUBY_PLATFORM
      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["patches"] = NOKOGIRI_LIBXML2_PATCHES
        else
          libxml["source"] = "system"
        end
        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["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
    elsif jruby?
      vi["xerces"] = Nokogiri::XERCES_VERSION
      vi["nekohtml"] = Nokogiri::NEKO_VERSION
    end
  end
end

#to_markdownObject


108
109
110
111
112
113
114
115
116
# File 'lib/nokogiri/version.rb', line 108

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


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nokogiri/version.rb', line 49

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