diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 2a40e1ad83..92450a771b 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -85,9 +85,9 @@ private Dependency.new(spec.to_s, tag) when :x11 then X11Dependency.new(spec.to_s, tag) when :xcode then XcodeDependency.new(tag) - when :mysql then MysqlInstalled.new(tag) - when :postgresql then PostgresqlInstalled.new(tag) - when :tex then TeXInstalled.new(tag) + when :mysql then MysqlDependency.new(tag) + when :postgresql then PostgresqlDependency.new(tag) + when :tex then TeXDependency.new(tag) when :clt then CLTDependency.new(tag) else raise "Unsupported special dependency #{spec}" diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 0c26b0da70..9ab455950b 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -13,6 +13,7 @@ class Requirement def initialize(*tags) @tags = tags.flatten.compact @tags << :build if self.class.build + @name ||= infer_name end # The message to show when the requirement is not met. @@ -55,6 +56,13 @@ class Requirement private + def infer_name + klass = self.class.to_s + klass.sub!(/(Dependency|Requirement)$/, '') + klass.sub!(/^(\w+::){0,}/, '') + klass.downcase + end + def infer_env_modification(o) case o when Pathname diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index e1a69661b3..f2d9dfeb8d 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -253,7 +253,7 @@ class XcodeDependency < Requirement end end -class MysqlInstalled < Requirement +class MysqlDependency < Requirement fatal true satisfy { which 'mysql_config' } @@ -274,7 +274,7 @@ class MysqlInstalled < Requirement end end -class PostgresqlInstalled < Requirement +class PostgresqlDependency < Requirement fatal true satisfy { which 'pg_config' } @@ -292,7 +292,7 @@ class PostgresqlInstalled < Requirement end end -class TeXInstalled < Requirement +class TeXDependency < Requirement fatal true satisfy { which('tex') || which('latex') } diff --git a/Library/Homebrew/test/test_requirement.rb b/Library/Homebrew/test/test_requirement.rb index ed7c37706f..682ee432e6 100644 --- a/Library/Homebrew/test/test_requirement.rb +++ b/Library/Homebrew/test/test_requirement.rb @@ -92,4 +92,12 @@ class RequirementTests < Test::Unit::TestCase req = Class.new(Requirement) { build true }.new assert req.build? end + + def test_infer_name_from_class + klass, const = self.class, :FooRequirement + klass.const_set(const, Class.new(Requirement)) + assert_equal "foo", klass.const_get(const).new.name + ensure + klass.send(:remove_const, const) if klass.const_defined?(const) + end end