specification.rb

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· RB 代码 · 共 661 行 · 第 1/2 页

RB
661
字号
        @description = str.strip.          gsub(/(\w-)\n[ \t]*(\w)/, '\1\2').          gsub(/\n[ \t]*/, " ")      end    end    overwrite_accessor :default_executable do      return @default_executable if @default_executable      # Special case: if there is only one executable specified, then      # that's obviously the default one.      return @executables.first if @executables.size == 1      nil    end    def add_bindir(executables)      if(@executables.nil?)         return nil      end      if(@bindir)        @executables.map {|e| File.join(@bindir, e) }      else        @executables      end    end    overwrite_accessor :files do      (@files || []) | (@test_files || []) | (add_bindir(@executables) || []) |        (@extra_rdoc_files || []) | (@extensions || [])    end    overwrite_accessor :test_files do      # Handle the possibility that we have @test_suite_file but not      # @test_files.  This will happen when an old gem is loaded via      # YAML.      if @test_suite_file        @test_files = [@test_suite_file].flatten        @test_suite_file = nil      end      @test_files ||= []    end    # Predicates -----------------------------------------------------        def loaded?; @loaded ? true : false ; end    def has_rdoc?; has_rdoc ? true : false ; end    def has_unit_tests?; not test_files.empty?; end    alias has_test_suite? has_unit_tests?               # (deprecated)        # Constructors ---------------------------------------------------        # Specification constructor.  Assigns the default values to the    # attributes, adds this spec to the list of loaded specs (see    # Specification.list), and yields itself for further initialization.    #    def initialize      # Each attribute has a default value (possibly nil).  Here, we      # initialize all attributes to their default value.  This is      # done through the accessor methods, so special behaviours will      # be honored.  Furthermore, we take a _copy_ of the default so      # each specification instance has its own empty arrays, etc.      @@attributes.each do |name, default|        if RUBY_VERSION >= "1.9" then          self.funcall "#{name}=", copy_of(default)        else          self.send "#{name}=", copy_of(default)        end      end      @loaded = false      @@list << self      yield self if block_given?      @@gather.call(self) if @@gather    end    # 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.     #    def Specification.from_yaml(input)      input = normalize_yaml_input(input)      spec = YAML.load(input)      if(spec.class == FalseClass) then        raise Gem::EndOfYAMLException      end      unless Specification === spec        raise Gem::Exception, "YAML data doesn't evaluate to gem specification"      end      unless spec.instance_variable_get :@specification_version        spec.instance_variable_set :@specification_version,           NONEXISTENT_SPECIFICATION_VERSION      end      spec    end     def Specification.load(filename)      gemspec = nil      fail "NESTED Specification.load calls not allowed!" if @@gather      @@gather = proc { |gs| gemspec = gs }      data = File.read(filename)      eval(data)      gemspec    ensure      @@gather = nil    end    # Make sure the yaml specification is properly formatted with dashes.    def Specification.normalize_yaml_input(input)      result = input.respond_to?(:read) ? input.read : input      result = "--- " + result unless result =~ /^--- /      result    end        # Instance methods -----------------------------------------------        # Sets the rubygems_version to Gem::RubyGemsVersion.    #    def mark_version      @rubygems_version = RubyGemsVersion    end    # Adds a dependency to this Gem.  For example,    #    #   spec.add_dependency('jabber4r', '> 0.1', '<= 0.5')    #    # gem:: [String or Gem::Dependency] The Gem name/dependency.    # requirements:: [default="> 0.0.0"] The version requirements.       #    def add_dependency(gem, *requirements)      requirements = ['> 0.0.0'] if requirements.empty?      requirements.flatten!      unless gem.respond_to?(:name) && gem.respond_to?(:version_requirements)        gem = Dependency.new(gem, requirements)      end      dependencies << gem    end        # Returns the full name (name-version) of this Gem.  Platform information    # is included (name-version-platform) if it is specified (and not the    # default Ruby platform).    #    def full_name      if platform == Gem::Platform::RUBY || platform.nil?        "#{@name}-#{@version}"      else        "#{@name}-#{@version}-#{platform}"      end     end        # The full path to the gem (install path + full name).    #    # return:: [String] the full gem path    #    def full_gem_path      File.join(installation_path, "gems", full_name)    end        # The root directory that the gem was installed into.    #    # return:: [String] the installation path    #    def installation_path      (File.dirname(@loaded_from).split(File::SEPARATOR)[0..-2]).        join(File::SEPARATOR)    end        # Checks if this Specification meets the requirement of the supplied    # dependency.    #     # dependency:: [Gem::Dependency] the dependency to check    # return:: [Boolean] true if dependency is met, otherwise false    #    def satisfies_requirement?(dependency)      return @name == dependency.name &&         dependency.version_requirements.satisfied_by?(@version)    end        # Comparison methods ---------------------------------------------        # Compare specs (name then version).    def <=>(other)      [@name, @version] <=> [other.name, other.version]    end    # Tests specs for equality (across all attributes).    def ==(other)      @@attributes.each do |name, default|        return false unless self.send(name) == other.send(name)      end      true    end        # Export methods (YAML and Ruby code) ----------------------------        # Returns an array of attribute names to be used when generating a    # YAML representation of this object.  If an attribute still has    # its default value, it is omitted.    def to_yaml_properties      mark_version      @@attributes.map { |name, default| "@#{name}" }    end    # 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 = "Gem::Specification.new do |s|\n"      @@attributes.each do |name, default|        # TODO better implementation of next line (read_only_attribute? ... something like that)        next if name == :dependencies or name == :specification_version        current_value = self.send(name)        result << "  s.#{name} = #{ruby_code(current_value)}\n" unless current_value == default      end      dependencies.each do |dep|        version_reqs_param = dep.requirements_list.inspect        result << "  s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})\n"      end      result << "end\n"    end    # Validation and normalization methods ---------------------------        # Checks that the specification contains all required fields, and    # does a very basic sanity check.    #    # Raises InvalidSpecificationException if the spec does not pass    # the checks..    def validate      normalize      if rubygems_version != RubyGemsVersion        raise InvalidSpecificationException.new(%[          Expected RubyGems Version #{RubyGemsVersion}, was #{rubygems_version}        ].strip)      end      @@required_attributes.each do |symbol|        unless self.send(symbol)          raise InvalidSpecificationException.new("Missing value for attribute #{symbol}")        end      end       if require_paths.empty?        raise InvalidSpecificationException.new("Gem spec needs to have at least one require_path")      end    end    # Normalize the list of files so that:    # * All file lists have redundancies removed.    # * Files referenced in the extra_rdoc_files are included in the    #   package file list.     #    # Also, the summary and description are converted to a normal    # format.     def normalize      if @extra_rdoc_files        @extra_rdoc_files.uniq!        @files ||= []        @files.concat(@extra_rdoc_files)      end      @files.uniq! if @files    end    # Dependency methods ---------------------------------------------        # Return a list of all gems that have a dependency on this    # gemspec.  The list is structured with entries that conform to:    #    #   [depending_gem, dependency, [list_of_gems_that_satisfy_dependency]]    #    # return:: [Array] [[dependent_gem, dependency, [list_of_satisfiers]]]    #    def dependent_gems      out = []      Gem.source_index.each do |name,gem|        gem.dependencies.each do |dep|          if self.satisfies_requirement?(dep) then            sats = []            find_all_satisfiers(dep) do |sat|              sats << sat            end            out << [gem, dep, sats]          end        end      end      out    end    def to_s      "#<Gem::Specification name=#{@name} version=#{@version}>"    end    private    def find_all_satisfiers(dep)      Gem.source_index.each do |name,gem|        if(gem.satisfies_requirement?(dep)) then          yield gem        end      end    end    # Duplicate an object unless it's an immediate value.    def copy_of(obj)      case obj      when Numeric, Symbol, true, false, nil then obj      else obj.dup      end    end    # Return a string containing a Ruby code representation of the    # given object.    def ruby_code(obj)      case obj      when String           then '%q{' + obj + '}'      when Array            then obj.inspect      when Gem::Version     then obj.to_s.inspect      when Date, Time       then '%q{' + obj.strftime('%Y-%m-%d') + '}'      when Numeric          then obj.inspect      when true, false, nil then obj.inspect      when Gem::Version::Requirement  then "Gem::Version::Requirement.new(#{obj.to_s.inspect})"      else raise Exception, "ruby_code case not handled: #{obj.class}"      end    end  endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?