ruby/lib/rubygems/specification.rb
##
# Returns a Ruby code representation of this specification, such that it can
# be eval'ed and reconstruct the same specification later.  Attributes that
# still have their default values are omitted.
Returns a Ruby code representation of this specification, such that it can
be eval'ed and reconstruct the same specification later.  Attributes that
still have their default values are omitted.
Returns a Ruby code representation of this specification such that it can be eval ' ed and reconstruct the same specification later . Attributes that still have their default values are omitted .
def to_ruby
    mark_version
    result = []
    result << "# -*- encoding: utf-8 -*-"
    result << "#{Gem::StubSpecification::PREFIX}#{name} #{version} #{platform} #{raw_require_paths.join("\0")}"
    result << "#{Gem::StubSpecification::PREFIX}#{extensions.join "\0"}" unless
      extensions.empty?
    result << nil
    result << "Gem::Specification.new do |s|"
    result << "  s.name = #{ruby_code name}"
    result << "  s.version = #{ruby_code version}"
    unless platform.nil? or platform == Gem::Platform::RUBY then
      result << "  s.platform = #{ruby_code original_platform}"
    end
    result << ""
    result << "  s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version="
    if metadata and !metadata.empty?
      result << "  s.metadata = #{ruby_code metadata} if s.respond_to? :metadata="
    end
    result << "  s.require_paths = #{ruby_code raw_require_paths}"
    handled = [
      :dependencies,
      :name,
      :platform,
      :require_paths,
      :required_rubygems_version,
      :specification_version,
      :version,
      :has_rdoc,
      :default_executable,
      :metadata
    ]
    @@attributes.each do |attr_name|
      next if handled.include? attr_name
      current_value = self.send(attr_name)
      if current_value != default_value(attr_name) or
         self.class.required_attribute? attr_name then
        result << "  s.#{attr_name} = #{ruby_code current_value}"
      end
    end
    if @installed_by_version then
      result << nil
      result << "  s.installed_by_version = \"#{Gem::VERSION}\" if s.respond_to? :installed_by_version"
    end
    unless dependencies.empty? then
      result << nil
      result << "  if s.respond_to? :specification_version then"
      result << "    s.specification_version = #{specification_version}"
      result << nil
      result << "    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then"
      dependencies.each do |dep|
        req = dep.requirements_list.inspect
        dep.instance_variable_set :@type, :runtime if dep.type.nil? 
        result << "      s.add_#{dep.type}_dependency(%q<#{dep.name}>.freeze, #{req})"
      end
      result << "    else"
      dependencies.each do |dep|
        version_reqs_param = dep.requirements_list.inspect
        result << "      s.add_dependency(%q<#{dep.name}>.freeze, #{version_reqs_param})"
      end
      result << '    end'
      result << "  else"
      dependencies.each do |dep|
        version_reqs_param = dep.requirements_list.inspect
        result << "    s.add_dependency(%q<#{dep.name}>.freeze, #{version_reqs_param})"
      end
      result << "  end"
    end
    result << "end"
    result << nil
    result.join "\n"
  end
def to_ruby mark_version result = [ ] result << "# -*- encoding: utf-8 -*-" result << "#{Gem::StubSpecification::PREFIX}#{name} #{version} #{platform} #{raw_require_paths.join("\0")}" result << "#{Gem::StubSpecification::PREFIX}#{extensions.join "\0"}" unless extensions . empty? result << nil result << "Gem::Specification.new do |s|" result << "  s.name = #{ruby_code name}" result << "  s.version = #{ruby_code version}" unless platform . nil? or platform == Gem :: Platform :: RUBY then result << "  s.platform = #{ruby_code original_platform}" end result << "" result << "  s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version=" if metadata and ! metadata . empty? result << "  s.metadata = #{ruby_code metadata} if s.respond_to? :metadata=" end result << "  s.require_paths = #{ruby_code raw_require_paths}" handled = [ :dependencies , :name , :platform , :require_paths , :required_rubygems_version , :specification_version , :version , :has_rdoc , :default_executable , :metadata ] @@attributes . each do | attr_name | next if handled . include? attr_name current_value = self . send ( attr_name ) if current_value != default_value ( attr_name ) or self . class . required_attribute? attr_name then result << "  s.#{attr_name} = #{ruby_code current_value}" end end if @installed_by_version then result << nil result << "  s.installed_by_version = \"#{Gem::VERSION}\" if s.respond_to? :installed_by_version" end unless dependencies . empty? then result << nil result << "  if s.respond_to? :specification_version then" result << "    s.specification_version = #{specification_version}" result << nil result << "    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then" dependencies . each do | dep | req = dep . requirements_list . inspect dep . instance_variable_set :@type , :runtime if dep . type . nil? result << "      s.add_#{dep.type}_dependency(%q<#{dep.name}>.freeze, #{req})" end result << "    else" dependencies . each do | dep | version_reqs_param = dep . requirements_list . inspect result << "      s.add_dependency(%q<#{dep.name}>.freeze, #{version_reqs_param})" end result << '    end' result << "  else" dependencies . each do | dep | version_reqs_param = dep . requirements_list . inspect result << "    s.add_dependency(%q<#{dep.name}>.freeze, #{version_reqs_param})" end result << "  end" end result << "end" result << nil result . join "\n" end
Returns a Ruby code representation of this specification, such that it can
be eval'ed and reconstruct the same specification later.
Returns a Ruby code representation of this specification such that it can be eval ' ed and reconstruct the same specification later .
# HACK