Class: Gel::Package::YAMLLoader

Inherits:
YAML::ClassLoader::Restricted
  • Object
show all
Defined in:
lib/gel/package.rb

Defined Under Namespace

Classes: Gem_Dependency, Gem_Platform, Gem_Requirement, Gem_Specification

Constant Summary collapse

Gem_Version =
Gel::Support::GemVersion

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeYAMLLoader

Returns a new instance of YAMLLoader.



72
73
74
# File 'lib/gel/package.rb', line 72

def initialize
  super(%w(Symbol Time), [])
end

Class Method Details

.load(yaml, filename) ⇒ Object

– Based on YAML.safe_load



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gel/package.rb', line 57

def self.load(yaml, filename)
  result = if Psych::VERSION < "3.1" # Ruby 2.5 & below
             ::YAML.parse(yaml, filename)
           else
             ::YAML.parse(yaml, filename: filename)
           end
  return unless result

  class_loader = self.new
  scanner      = ::YAML::ScalarScanner.new class_loader

  visitor = ::YAML::Visitors::ToRuby.new scanner, class_loader
  visitor.accept result
end

Instance Method Details

#find(klass) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gel/package.rb', line 76

def find(klass)
  case klass
  when "Gem::Specification"
    Gem_Specification
  when "Gem::Version"
    Gem_Version
  when "Gem::Version::Requirement", "Gem::Requirement"
    Gem_Requirement
  when "Gem::Platform"
    Gem_Platform
  when "Gem::Dependency"
    Gem_Dependency
  else
    super
  end
end