specification.rb
来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· RB 代码 · 共 661 行 · 第 1/2 页
RB
661 行
#--# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.# All rights reserved.# See LICENSE.txt for permissions.#++require 'time'require 'rubygems'require 'rubygems/version'class Time def self.today Time.parse Time.now.strftime("%Y-%m-%d") endendmodule Gem # == Gem::Platform # # Available list of platforms for targeting Gem installations. # Platform::RUBY is the default platform (pure Ruby Gem). # module Platform RUBY = 'ruby' WIN32 = 'mswin32' LINUX_586 = 'i586-linux' DARWIN = 'powerpc-darwin' CURRENT = 'current' end # Potentially raised when a specification is validated. class InvalidSpecificationException < Gem::Exception; end class EndOfYAMLException < Gem::Exception; end # == Gem::Specification # # The Specification class contains the metadata for a Gem. Typically defined in a # .gemspec file or a Rakefile, and looks like this: # # spec = Gem::Specification.new do |s| # s.name = 'rfoo' # s.version = '1.0' # s.summary = 'Example gem specification' # ... # end # # There are many <em>gemspec attributes</em>, and the best place to learn about them in # the "Gemspec Reference" linked from the RubyGems wiki. # class Specification # ------------------------- Specification version contstants. # The the version number of a specification that does not specify one (i.e. RubyGems 0.7 # or earlier). NONEXISTENT_SPECIFICATION_VERSION = -1 # The specification version applied to any new Specification instances created. This # should be bumped whenever something in the spec format changes. CURRENT_SPECIFICATION_VERSION = 1 # An informal list of changes to the specification. The highest-valued key should be # equal to the CURRENT_SPECIFICATION_VERSION. SPECIFICATION_VERSION_HISTORY = { -1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'], 1 => [ 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"', '"test_file=x" is a shortcut for "test_files=[x]"' ] } # ------------------------- Class variables. # List of Specification instances. @@list = [] # Optional block used to gather newly defined instances. @@gather = nil # List of attribute names: [:name, :version, ...] @@required_attributes = [] # List of _all_ attributes and default values: [[:name, nil], [:bindir, 'bin'], ...] @@attributes = [] # List of array attributes @@array_attributes = [] # Map of attribute names to default values. @@default_value = {} # ------------------------- Convenience class methods. def self.attribute_names @@attributes.map { |name, default| name } end def self.attribute_defaults @@attributes.dup end def self.default_value(name) @@default_value[name] end def self.required_attributes @@required_attributes.dup end def self.required_attribute?(name) @@required_attributes.include? name.to_sym end def self.array_attributes @@array_attributes.dup end # ------------------------- Infrastructure class methods. # A list of Specification instances that have been defined in this Ruby instance. def self.list @@list end # Used to specify the name and default value of a specification # attribute. The side effects are: # * the name and default value are added to the @@attributes list # and @@default_value map # * a standard _writer_ method (<tt>attribute=</tt>) is created # * a non-standard _reader method (<tt>attribute</tt>) is created # # The reader method behaves like this: # def attribute # @attribute ||= (copy of default value) # end # # This allows lazy initialization of attributes to their default # values. # def self.attribute(name, default=nil) @@attributes << [name, default] @@default_value[name] = default attr_accessor(name) end # Same as :attribute, but ensures that values assigned to the # attribute are array values by applying :to_a to the value. def self.array_attribute(name) @@array_attributes << name @@attributes << [name, []] @@default_value[name] = [] module_eval %{ def #{name} @#{name} ||= [] end def #{name}=(value) @#{name} = value.to_a end } end # Same as attribute above, but also records this attribute as mandatory. def self.required_attribute(*args) @@required_attributes << args.first attribute(*args) end # Sometimes we don't want the world to use a setter method for a particular attribute. # +read_only+ makes it private so we can still use it internally. def self.read_only(*names) names.each do |name| private "#{name}=" end end # Shortcut for creating several attributes at once (each with a default value of # +nil+). def self.attributes(*args) args.each do |arg| attribute(arg, nil) end end # Some attributes require special behaviour when they are accessed. This allows for # that. def self.overwrite_accessor(name, &block) remove_method name define_method(name, &block) end # Defines a _singular_ version of an existing _plural_ attribute # (i.e. one whose value is expected to be an array). This means # just creating a helper method that takes a single value and # appends it to the array. These are created for convenience, so # that in a spec, one can write # # s.require_path = 'mylib' # # instead of # # s.require_paths = ['mylib'] # # That above convenience is available courtesy of # # attribute_alias_singular :require_path, :require_paths # def self.attribute_alias_singular(singular, plural) define_method("#{singular}=") { |val| send("#{plural}=", [val]) } define_method("#{singular}") { val = send("#{plural}") val.nil? ? nil : val.first } end def warn_deprecated(old, new) # How (if at all) to implement this? We only want to warn when # a gem is being built, I should think. end # REQUIRED gemspec attributes ------------------------------------ required_attribute :rubygems_version, RubyGemsVersion required_attribute :specification_version, CURRENT_SPECIFICATION_VERSION required_attribute :name required_attribute :version required_attribute :date required_attribute :summary required_attribute :require_paths, ['lib'] read_only :specification_version # OPTIONAL gemspec attributes ------------------------------------ attributes :email, :homepage, :rubyforge_project, :description attributes :autorequire, :default_executable attribute :bindir, 'bin' attribute :has_rdoc, false attribute :required_ruby_version, Gem::Version::Requirement.default attribute :platform, Gem::Platform::RUBY attribute :signing_key, nil attribute :cert_chain, nil attribute :post_install_message, nil array_attribute :authors array_attribute :files array_attribute :test_files array_attribute :rdoc_options array_attribute :extra_rdoc_files array_attribute :executables array_attribute :extensions array_attribute :requirements array_attribute :dependencies read_only :dependencies # ALIASED gemspec attributes ------------------------------------- attribute_alias_singular :executable, :executables attribute_alias_singular :author, :authors attribute_alias_singular :require_path, :require_paths attribute_alias_singular :test_file, :test_files # DEPRECATED gemspec attributes ---------------------------------- def test_suite_file warn_deprecated(:test_suite_file, :test_files) test_files.first end def test_suite_file=(val) warn_deprecated(:test_suite_file, :test_files) @test_files << val end # RUNTIME attributes (not persisted) ----------------------------- attr_writer :loaded attr_accessor :loaded_from # Special accessor behaviours (overwriting default) -------------- overwrite_accessor :version= do |version| @version = Version.create(version) end overwrite_accessor :platform= do |platform| # Checks the provided platform for the special value # Platform::CURRENT and changes it to be binary specific to the # current platform (i386-mswin32, etc). @platform = (platform == Platform::CURRENT ? RUBY_PLATFORM : platform) end overwrite_accessor :required_ruby_version= do |value| @required_ruby_version = Version::Requirement.create(value) end overwrite_accessor :date= do |date| # We want to end up with a Time object with one-day resolution. # This is the cleanest, most-readable, faster-than-using-Date # way to do it. case date when String then @date = Time.parse date when Time then @date = Time.parse date.strftime("%Y-%m-%d") when Date then @date = Time.parse date.to_s else @date = Time.today end end overwrite_accessor :date do self.date = nil if @date.nil? # HACK Sets the default value for date @date end overwrite_accessor :summary= do |str| if str @summary = str.strip. gsub(/(\w-)\n[ \t]*(\w)/, '\1\2'). gsub(/\n[ \t]*/, " ") end end overwrite_accessor :description= do |str| if str
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?