formula: add/improve more API docs.

Closes Homebrew/homebrew#35266.
This commit is contained in:
Mike McQuaid 2014-12-26 20:24:12 +00:00
parent 80aef5fdb9
commit dc7b54ae43

View File

@ -51,9 +51,9 @@ class Formula
# @see #stable # @see #stable
attr_reader :head attr_reader :head
# The currently active SoftwareSpec. # The currently active {SoftwareSpec}.
# Defaults to stable unless `--devel` or `--HEAD` is passed. # Defaults to stable unless `--devel` or `--HEAD` is passed.
# @api private # @private
attr_reader :active_spec attr_reader :active_spec
# The {PkgVersion} for this formula with version and {#revision} information. # The {PkgVersion} for this formula with version and {#revision} information.
@ -82,6 +82,7 @@ class Formula
# state that we're trying to eliminate. # state that we're trying to eliminate.
attr_accessor :build attr_accessor :build
# @private
def initialize(name, path, spec) def initialize(name, path, spec)
@name = name @name = name
@path = path @path = path
@ -123,82 +124,120 @@ class Formula
public public
# Is the currently active {SoftwareSpec} a {#stable} build?
def stable? def stable?
active_spec == stable active_spec == stable
end end
# Is the currently active {SoftwareSpec} a {#devel} build?
def devel? def devel?
active_spec == devel active_spec == devel
end end
# Is the currently active {SoftwareSpec} a {#head} build?
def head? def head?
active_spec == head active_spec == head
end end
# The Bottle object for the currently active {SoftwareSpec}.
# @private
def bottle def bottle
Bottle.new(self, active_spec.bottle_specification) if active_spec.bottled? Bottle.new(self, active_spec.bottle_specification) if active_spec.bottled?
end end
# The homepage for the software.
# @see .homepage
def homepage def homepage
self.class.homepage self.class.homepage
end end
def url; active_spec.url; end # The URL used to download the source for the currently active {SoftwareSpec}.
def version; active_spec.version; end # @see .url
# @deprecated
# @private
def url
active_spec.url
end
# The version for the currently active {SoftwareSpec}.
# The version is autodetected from the URL and/or tag so only needs to be
# declared if it cannot be autodetected correctly.
# @see .version
def version
active_spec.version
end
# A named Resource for the currently active {SoftwareSpec}.
def resource(name) def resource(name)
active_spec.resource(name) active_spec.resource(name)
end end
# The {Resource}s for the currently active {SoftwareSpec}.
def resources def resources
active_spec.resources.values active_spec.resources.values
end end
# The {Dependency}s for the currently active {SoftwareSpec}.
def deps def deps
active_spec.deps active_spec.deps
end end
# The {Requirement}s for the currently active {SoftwareSpec}.
def requirements def requirements
active_spec.requirements active_spec.requirements
end end
# The cached download of {.url} for the currently active {SoftwareSpec}.
def cached_download def cached_download
active_spec.cached_download active_spec.cached_download
end end
# Deletes the download of {.url} for the currently active {SoftwareSpec}.
def clear_cache def clear_cache
active_spec.clear_cache active_spec.clear_cache
end end
# The list of patches for the currently active {SoftwareSpec}.
def patchlist def patchlist
active_spec.patches active_spec.patches
end end
# The options for the currently active {SoftwareSpec}.
def options def options
active_spec.options active_spec.options
end end
# The deprecated options for the currently active {SoftwareSpec}.
def deprecated_options def deprecated_options
active_spec.deprecated_options active_spec.deprecated_options
end end
# If a named option is defined for the currently active {SoftwareSpec}.
def option_defined?(name) def option_defined?(name)
active_spec.option_defined?(name) active_spec.option_defined?(name)
end end
# All the {.fails_with} for the currently active {SoftwareSpec}.
def compiler_failures def compiler_failures
active_spec.compiler_failures active_spec.compiler_failures
end end
# if the dir is there, but it's empty we consider it not installed # If this {Formula} is installed.
# This is actually just a check for if the {#installed_prefix} directory
# exists and is not empty.
def installed? def installed?
(dir = installed_prefix).directory? && dir.children.length > 0 (dir = installed_prefix).directory? && dir.children.length > 0
end end
# @deprecated
# The `LinkedKegs` directory for this {Formula}.
# You probably want {.opt_prefix} instead.
def linked_keg def linked_keg
Pathname.new("#{HOMEBREW_LIBRARY}/LinkedKegs/#{name}") Pathname.new("#{HOMEBREW_LIBRARY}/LinkedKegs/#{name}")
end end
# The latest prefix for this formula. Checks for {#head}, then #{devel}
# and then #{stable}'s #{.prefix}
def installed_prefix def installed_prefix
if head && (head_prefix = prefix(head.version)).directory? if head && (head_prefix = prefix(head.version)).directory?
head_prefix head_prefix
@ -329,7 +368,7 @@ class Formula
end end
# yields self with current working directory set to the uncompressed tarball # yields self with current working directory set to the uncompressed tarball
# @api private # @private
def brew def brew
validate_attributes :name, :version validate_attributes :name, :version
@ -419,7 +458,7 @@ class Formula
alias_method :python2, :python alias_method :python2, :python
alias_method :python3, :python alias_method :python3, :python
# an array of all Formula names # an array of all {Formula} names
def self.names def self.names
Dir["#{HOMEBREW_LIBRARY}/Formula/*.rb"].map{ |f| File.basename f, '.rb' }.sort Dir["#{HOMEBREW_LIBRARY}/Formula/*.rb"].map{ |f| File.basename f, '.rb' }.sort
end end
@ -437,7 +476,7 @@ class Formula
end end
end end
# An array of all installed formulae # An array of all installed {Formula}
def self.installed def self.installed
return [] unless HOMEBREW_CELLAR.directory? return [] unless HOMEBREW_CELLAR.directory?
@ -725,23 +764,23 @@ class Formula
# The reason for why this software is not linked (by default) to # The reason for why this software is not linked (by default) to
# {::HOMEBREW_PREFIX}. # {::HOMEBREW_PREFIX}.
# @api private # @private
attr_reader :keg_only_reason attr_reader :keg_only_reason
# @!attribute [rw] # @!attribute [rw]
# The homepage for the software. Used by users to get more information # The homepage for the software. Used by users to get more information
# about the software and Homebrew maintainers as a point of contact for # about the software and Homebrew maintainers as a point of contact for
# e.g. submitting patches. # e.g. submitting patches.
# Can be opened by running `brew home example-formula`. # Can be opened with running `brew home`.
attr_rw :homepage attr_rw :homepage
# @!attribute [rw]
# The `:startup` attribute set by {.plist_options}. # The `:startup` attribute set by {.plist_options}.
attr_rw :plist_startup # @private
attr_reader :plist_startup
# @!attribute [rw]
# The `:manual` attribute set by {.plist_options}. # The `:manual` attribute set by {.plist_options}.
attr_rw :plist_manual # @private
attr_reader :plist_manual
# @!attribute [rw] # @!attribute [rw]
# Used for creating new Homebrew versions of software without new upstream # Used for creating new Homebrew versions of software without new upstream
@ -751,22 +790,48 @@ class Formula
# `0` if unset. # `0` if unset.
attr_rw :revision attr_rw :revision
# A list of the {.stable}, {.devel} and {.head} {SoftwareSpec}s.
# @private
def specs def specs
@specs ||= [stable, devel, head].freeze @specs ||= [stable, devel, head].freeze
end end
# @!attribute [rw] url
# The URL used to download the source for the currently active {SoftwareSpec}.
# We prefer `https` for security and proxy reasons.
def url val, specs={} def url val, specs={}
stable.url(val, specs) stable.url(val, specs)
end end
# @!attribute [w] version
# The version for the currently active {SoftwareSpec}.
# The version is autodetected from the URL and/or tag so only needs to be
# declared if it cannot be autodetected correctly.
def version val=nil def version val=nil
stable.version(val) stable.version(val)
end end
# @!attribute [rw] mirror
# Additional {.url}s for the currently active {SoftwareSpec}.
# These are only used if the {.url} fails to download. It's optional and
# there can be more than one. Generally we add them when the main {.url}
# is unreliable. If {.url} is really unreliable then we may swap the
# {.mirror} and {.url}.
def mirror val def mirror val
stable.mirror(val) stable.mirror(val)
end end
# @!attribute [rw] sha1
# @scope class
# To verify the {#cached_download}'s integrity and security we verify the
# SHA-1 hash matches what we've declared in the {Formula}. To quickly fill
# this value you can leave it blank and run `brew fetch --force` and it'll
# tell you the currently valid value.
# @!attribute [rw] sha256
# @scope class
# Similar to {.sha1} but using a SHA-256 hash instead.
Checksum::TYPES.each do |type| Checksum::TYPES.each do |type|
define_method(type) { |val| stable.send(type, val) } define_method(type) { |val| stable.send(type, val) }
end end
@ -802,7 +867,7 @@ class Formula
end end
end end
# Define a named resource using a SoftwareSpec style block # Define a named resource using a {SoftwareSpec} style block
def resource name, klass=Resource, &block def resource name, klass=Resource, &block
specs.each do |spec| specs.each do |spec|
spec.resource(name, klass, &block) unless spec.resource_defined?(name) spec.resource(name, klass, &block) unless spec.resource_defined?(name)