Reuse container class test function with API

This commit is contained in:
Jason Perkins 2014-11-24 15:26:57 -05:00
parent dfc24eccfa
commit 75814c3e3b
3 changed files with 17 additions and 13 deletions

View File

@ -466,11 +466,8 @@
-- compatibile with this scope, then I can use it.
local currentClass = api.scope.current.class
local targetClass = p.container.getClass(scope)
while targetClass do
if targetClass.name == currentClass.name then
return api.scope.current
end
targetClass = targetClass.parent
if p.container.classIsA(targetClass, currentClass.name) then
return api.scope.current
end
end

View File

@ -235,20 +235,27 @@
---
-- Return true if the container is or inherits from specified class.
-- Return true if a container class is or inherits from the
-- specified class.
--
-- @param className
-- The name of the class to check against.
-- @param class
-- The container class to be tested.
-- @param scope
-- The name of the class to be checked against. If the container
-- class matches this scope (i.e. class is a project and the
-- scope is "project"), or if it is a parent object of it (i.e.
-- class is a solution and scope is "project"), then returns
-- true.
---
function container.hasClass(self, className)
local class = self.class
while class.parent do
if class.name == className then
function container.classIsA(class, scope)
while class do
if class.name == scope then
return true
end
class = class.parent
end
return false
end

View File

@ -115,7 +115,7 @@
-- I can skip over it (config scope applies to everything).
local scope
for i = 1, #f.scopes do
if f.scopes[i] == "config" or p.container.hasClass(container, f.scopes[i]) then
if f.scopes[i] == "config" or p.container.classIsA(container.class, f.scopes[i]) then
scope = f.scopes[i]
break
end