Method: LibGems::SourceIndex.load_specification

Defined in:
lib/libgems/source_index.rb

.load_specification(file_name) ⇒ Object

Loads a ruby-format specification from file_name and returns the loaded spec.



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
# File 'lib/libgems/source_index.rb', line 85

def load_specification(file_name)
  return nil unless file_name and File.exist? file_name

  spec_code = if defined? Encoding then
                File.read file_name, :encoding => 'UTF-8'
              else
                File.read file_name
              end.untaint

  begin
    gemspec = LibGems.with_rubygems_compat{ eval(spec_code, binding, file_name) }

    if gemspec.is_a?(LibGems::Specification)
      gemspec.loaded_from = file_name
      return gemspec
    end
    alert_warning "File '#{file_name}' does not evaluate to a gem specification"
  rescue SignalException, SystemExit
    raise
  rescue SyntaxError => e
    alert_warning e
    alert_warning spec_code
  rescue Exception => e
    alert_warning "#{e.inspect}\n#{spec_code}"
    alert_warning "Invalid .gemspec format in '#{file_name}'"
  end

  return nil
end