Method: LibGems::Specification.from_yaml

Defined in:
lib/libgems/specification.rb

.from_yaml(input) ⇒ Object

Special loader for YAML files. When a Specification object is loaded from a YAML file, it bypasses the normal Ruby object initialization routine (#initialize). This method makes up for that and deals with gems of different ages.

‘input’ can be anything that YAML.load() accepts: String or IO.



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/libgems/specification.rb', line 478

def self.from_yaml(input)
  input = normalize_yaml_input input
  spec = LibGems.with_rubygems_compat{ YAML.load input }

  if spec && spec.class == FalseClass then
    raise LibGems::EndOfYAMLException
  end

  unless LibGems::Specification === spec then
    raise LibGems::Exception, "YAML data doesn't evaluate to gem specification"
  end

  unless (spec.instance_variables.include? '@specification_version' or
          spec.instance_variables.include? :@specification_version) and
         spec.instance_variable_get :@specification_version
    spec.instance_variable_set :@specification_version,
                               NONEXISTENT_SPECIFICATION_VERSION
  end

  spec
end