aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-08-12 23:55:28 -0500
committerJack Nagel2014-08-12 23:55:28 -0500
commit8d2ef974a3a87bf4207f71ccb8a7b4776e16a016 (patch)
treef25128e58aab34cb381d7573a93cbeba78d017f2
parentcee42c339e7632eab15111e2c4e6c121ace6f9e2 (diff)
downloadhomebrew-8d2ef974a3a87bf4207f71ccb8a7b4776e16a016.tar.bz2
Replace Options.coerce with an alternate constructor
-rw-r--r--Library/Homebrew/dependable.rb2
-rw-r--r--Library/Homebrew/formula_installer.rb2
-rw-r--r--Library/Homebrew/options.rb31
-rw-r--r--Library/Homebrew/software_spec.rb2
-rw-r--r--Library/Homebrew/tab.rb4
-rw-r--r--Library/Homebrew/test/test_build_options.rb4
-rw-r--r--Library/Homebrew/test/test_options.rb12
7 files changed, 24 insertions, 33 deletions
diff --git a/Library/Homebrew/dependable.rb b/Library/Homebrew/dependable.rb
index d500cd033..f1951e4c6 100644
--- a/Library/Homebrew/dependable.rb
+++ b/Library/Homebrew/dependable.rb
@@ -24,6 +24,6 @@ module Dependable
end
def options
- Options.coerce(tags - RESERVED_TAGS)
+ Options.create(tags - RESERVED_TAGS)
end
end
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index 02e61587b..d9e72702b 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -465,7 +465,7 @@ class FormulaInstaller
end
def build_argv
- opts = Options.coerce(sanitized_ARGV_options)
+ opts = Options.create(sanitized_ARGV_options)
opts.concat(options)
opts
end
diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb
index 86be67ea9..a612f27fe 100644
--- a/Library/Homebrew/options.rb
+++ b/Library/Homebrew/options.rb
@@ -53,6 +53,19 @@ class Options
attr_reader :options
protected :options
+ def self.create(array)
+ options = new
+ array.each do |e|
+ case e
+ when /^-[^-]+$/
+ e[1..-1].split(//).each { |o| options << Option.new(o) }
+ else
+ options << Option.new(e)
+ end
+ end
+ options
+ end
+
def initialize(*args)
@options = Set.new(*args)
end
@@ -113,22 +126,4 @@ class Options
def inspect
"#<#{self.class.name}: #{to_a.inspect}>"
end
-
- def self.coerce(arg)
- case arg
- when Array
- opts = new
- arg.each do |a|
- case a
- when /^-[^-]+$/
- a[1..-1].split(//).each { |o| opts << Option.new(o) }
- else
- opts << Option.new(a)
- end
- end
- opts
- else
- raise TypeError, "Cannot convert #{arg.inspect} to Options"
- end
- end
end
diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb
index e88975a73..9fda2cef9 100644
--- a/Library/Homebrew/software_spec.rb
+++ b/Library/Homebrew/software_spec.rb
@@ -34,7 +34,7 @@ class SoftwareSpec
@bottle_specification = BottleSpecification.new
@patches = []
@options = Options.new
- @build = BuildOptions.new(Options.coerce(ARGV.options_only), options)
+ @build = BuildOptions.new(Options.create(ARGV.options_only), options)
end
def owner= owner
diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb
index edba1d0e6..daf701591 100644
--- a/Library/Homebrew/tab.rb
+++ b/Library/Homebrew/tab.rb
@@ -106,11 +106,11 @@ class Tab < OpenStruct
end
def used_options
- Options.coerce(super)
+ Options.create(super)
end
def unused_options
- Options.coerce(super)
+ Options.create(super)
end
def cxxstdlib
diff --git a/Library/Homebrew/test/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb
index a0c52da81..7d2c952d9 100644
--- a/Library/Homebrew/test/test_build_options.rb
+++ b/Library/Homebrew/test/test_build_options.rb
@@ -4,8 +4,8 @@ require "options"
class BuildOptionsTests < Homebrew::TestCase
def setup
- args = Options.coerce(%w(--with-foo --with-bar --without-qux))
- opts = Options.coerce(%w(--with-foo --with-bar --without-baz --without-qux))
+ args = Options.create(%w(--with-foo --with-bar --without-qux))
+ opts = Options.create(%w(--with-foo --with-bar --without-baz --without-qux))
@build = BuildOptions.new(args, opts)
end
diff --git a/Library/Homebrew/test/test_options.rb b/Library/Homebrew/test/test_options.rb
index 250360a30..264ef772a 100644
--- a/Library/Homebrew/test/test_options.rb
+++ b/Library/Homebrew/test/test_options.rb
@@ -132,22 +132,18 @@ class OptionsTests < Homebrew::TestCase
assert_equal [foo, bar, baz].sort, (@options | options).to_a.sort
end
- def test_coerce_with_array
+ def test_create_with_array
array = %w{--foo --bar}
option1 = Option.new("foo")
option2 = Option.new("bar")
- assert_equal [option1, option2].sort, Options.coerce(array).to_a.sort
+ assert_equal [option1, option2].sort, Options.create(array).to_a.sort
end
- def test_coerce_raises_for_inappropriate_types
- assert_raises(TypeError) { Options.coerce(1) }
- end
-
- def test_coerce_splits_multiple_switches_with_single_dash
+ def test_create_splits_multiple_switches_with_single_dash
array = %w{-vd}
verbose = Option.new("-v")
debug = Option.new("-d")
- assert_equal [verbose, debug].sort, Options.coerce(array).to_a.sort
+ assert_equal [verbose, debug].sort, Options.create(array).to_a.sort
end
def test_copies_do_not_share_underlying_collection