Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Establish a convention for Requirement names

The name attribute of requirements is used when generating options for
the :optional and :recommended dependency tags.

Unless otherwise specified, the name attribute of a Requirement will be
populated by stripping any module prefixes from the beginning and
"Dependency" or "Requirement" from end of the class name and downcasing
the result.

Closes #17759.
  • Loading branch information...
commit c4db67fc9b842de8d41706cfaf8860651d4360ec 1 parent 0174909
@jacknagel jacknagel authored
View
6 Library/Homebrew/dependency_collector.rb
@@ -85,9 +85,9 @@ def parse_symbol_spec spec, tag
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}"
View
8 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 @@ def hash
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
View
6 Library/Homebrew/requirements.rb
@@ -253,7 +253,7 @@ def message; <<-EOS.undent
end
end
-class MysqlInstalled < Requirement
+class MysqlDependency < Requirement
fatal true
satisfy { which 'mysql_config' }
@@ -274,7 +274,7 @@ def message; <<-EOS.undent
end
end
-class PostgresqlInstalled < Requirement
+class PostgresqlDependency < Requirement
fatal true
satisfy { which 'pg_config' }
@@ -292,7 +292,7 @@ def message
end
end
-class TeXInstalled < Requirement
+class TeXDependency < Requirement
fatal true
satisfy { which('tex') || which('latex') }
View
8 Library/Homebrew/test/test_requirement.rb
@@ -92,4 +92,12 @@ def test_dsl_build
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
Please sign in to comment.
Something went wrong with that request. Please try again.