Extract attr_rw from Formula for reuse

Closes Homebrew/homebrew#20239.
This commit is contained in:
Jack Nagel 2013-06-04 11:05:02 -05:00
parent 8781950294
commit b97b013fce
7 changed files with 18 additions and 47 deletions

View File

@ -6,19 +6,12 @@ end
class CompilerFailure
attr_reader :compiler
attr_rw :build, :cause
def initialize compiler, &block
@compiler = compiler
instance_eval(&block) if block_given?
@build ||= 9999
end
def build val=nil
val.nil? ? @build.to_i : @build = val.to_i
end
def cause val=nil
val.nil? ? @cause : @cause = val
@build = (@build || 9999).to_i
end
end

View File

@ -0,0 +1,11 @@
class Module
def attr_rw(*attrs)
attrs.each do |attr|
module_eval <<-EOS, __FILE__, __LINE__ + 1
def #{attr}(val=nil)
val.nil? ? @#{attr} : @#{attr} = val
end
EOS
end
end
end

View File

@ -688,16 +688,6 @@ class Formula
class << self
# The methods below define the formula DSL.
def self.attr_rw(*attrs)
attrs.each do |attr|
class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{attr}(val=nil)
val.nil? ? @#{attr} : @#{attr} = val
end
EOS
end
end
attr_rw :homepage, :keg_only_reason, :skip_clean_all, :cc_failures
attr_rw :plist_startup, :plist_manual

View File

@ -77,6 +77,7 @@ end
class Bottle < SoftwareSpec
attr_writer :url
attr_rw :root_url, :prefix, :cellar, :revision
def initialize
super
@ -103,22 +104,6 @@ class Bottle < SoftwareSpec
end
EOS
end
def root_url val=nil
val.nil? ? @root_url : @root_url = val
end
def prefix val=nil
val.nil? ? @prefix : @prefix = val
end
def cellar val=nil
val.nil? ? @cellar : @cellar = val
end
def revision val=nil
val.nil? ? @revision : @revision = val
end
end

View File

@ -1,3 +1,4 @@
require 'extend/module'
require 'extend/fileutils'
require 'extend/pathname'
require 'extend/ARGV'

View File

@ -88,18 +88,7 @@ class Requirement
end
class << self
# The default formula to install to satisfy this requirement.
def default_formula(val=nil)
val.nil? ? @default_formula : @default_formula = val.to_s
end
def fatal(val=nil)
val.nil? ? @fatal : @fatal = val
end
def build(val=nil)
val.nil? ? @build : @build = val
end
attr_rw :fatal, :build, :default_formula
def satisfy(options={}, &block)
@satisfied ||= Requirement::Satisfier.new(options, &block)

View File

@ -7,9 +7,11 @@
ABS__FILE__ = File.expand_path(__FILE__)
$:.push(File.expand_path(__FILE__+'/../..'))
require 'extend/module'
require 'extend/fileutils'
require 'extend/pathname'
require 'extend/string'
require 'extend/symbol'
require 'exceptions'
require 'utils'
require 'rbconfig'