aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2013-06-04 11:05:02 -0500
committerJack Nagel2013-06-04 11:06:18 -0500
commitb97b013fcea50c783faf85e7c12f7844eb86e4b3 (patch)
treeb6b12ee2f83044d7ab57e96331a48325520fccd6
parent87819502945c546ff3356804ffd857df7d5406fa (diff)
downloadbrew-b97b013fcea50c783faf85e7c12f7844eb86e4b3.tar.bz2
Extract attr_rw from Formula for reuse
Closes Homebrew/homebrew#20239.
-rw-r--r--Library/Homebrew/compilers.rb11
-rw-r--r--Library/Homebrew/extend/module.rb11
-rw-r--r--Library/Homebrew/formula.rb10
-rw-r--r--Library/Homebrew/formula_support.rb17
-rw-r--r--Library/Homebrew/global.rb1
-rw-r--r--Library/Homebrew/requirement.rb13
-rw-r--r--Library/Homebrew/test/testing_env.rb2
7 files changed, 18 insertions, 47 deletions
diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb
index 43d8ea900..80826237a 100644
--- a/Library/Homebrew/compilers.rb
+++ b/Library/Homebrew/compilers.rb
@@ -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
diff --git a/Library/Homebrew/extend/module.rb b/Library/Homebrew/extend/module.rb
new file mode 100644
index 000000000..9210793f6
--- /dev/null
+++ b/Library/Homebrew/extend/module.rb
@@ -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
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 4a24552ef..ed251f6b0 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -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
diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb
index 85f215ade..a36f5a387 100644
--- a/Library/Homebrew/formula_support.rb
+++ b/Library/Homebrew/formula_support.rb
@@ -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
diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb
index 46b48268a..edfce9ac4 100644
--- a/Library/Homebrew/global.rb
+++ b/Library/Homebrew/global.rb
@@ -1,3 +1,4 @@
+require 'extend/module'
require 'extend/fileutils'
require 'extend/pathname'
require 'extend/ARGV'
diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb
index dcacf45e0..03a3ffd39 100644
--- a/Library/Homebrew/requirement.rb
+++ b/Library/Homebrew/requirement.rb
@@ -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)
diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb
index 817346bef..8e93884eb 100644
--- a/Library/Homebrew/test/testing_env.rb
+++ b/Library/Homebrew/test/testing_env.rb
@@ -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'