mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
removes default includes(mixin) method and __mixins attribute
This commit is contained in:
parent
d5776a20ed
commit
0f20fc4288
@ -109,7 +109,7 @@ local function _setClassMetatable(aClass)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function _createClass(name, super)
|
local function _createClass(name, super)
|
||||||
local aClass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict = {}, __instanceMeta = {} }
|
local aClass = { name = name, super = super, static = {}, __instanceDict = {}, __instanceMeta = {} }
|
||||||
aClass.subclasses = setmetatable({}, {__mode = "k"})
|
aClass.subclasses = setmetatable({}, {__mode = "k"})
|
||||||
|
|
||||||
_setClassDictionariesMetatables(aClass)
|
_setClassDictionariesMetatables(aClass)
|
||||||
@ -141,7 +141,6 @@ local function _includeMixin(aClass, mixin)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if type(mixin.included)=="function" then mixin:included(aClass) end
|
if type(mixin.included)=="function" then mixin:included(aClass) end
|
||||||
aClass.__mixins[mixin] = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local Object = {
|
local Object = {
|
||||||
@ -199,17 +198,6 @@ local Object = {
|
|||||||
assert(type(self) == 'table', "Make sure you that you are using 'Class:include' instead of 'Class.include'")
|
assert(type(self) == 'table', "Make sure you that you are using 'Class:include' instead of 'Class.include'")
|
||||||
for _,mixin in ipairs({...}) do _includeMixin(self, mixin) end
|
for _,mixin in ipairs({...}) do _includeMixin(self, mixin) end
|
||||||
return self
|
return self
|
||||||
end,
|
|
||||||
|
|
||||||
includes = function(self, mixin)
|
|
||||||
return type(mixin) == 'table' and
|
|
||||||
type(self) == 'table' and
|
|
||||||
type(self.__mixins) == 'table' and
|
|
||||||
( self.__mixins[mixin] or
|
|
||||||
type(self.super) == 'table' and
|
|
||||||
type(self.super.includes) == 'function' and
|
|
||||||
self.super:includes(mixin)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,73 +260,6 @@ describe('Default methods', function()
|
|||||||
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('includes', function()
|
|
||||||
|
|
||||||
describe('nils, numbers, etc', function()
|
|
||||||
local o = Object:new()
|
|
||||||
local primitives = {nil, 1, 'hello', {}, function() end}
|
|
||||||
|
|
||||||
for _,primitive in pairs(primitives) do
|
|
||||||
local theType = type(primitive)
|
|
||||||
describe('A ' .. theType, function()
|
|
||||||
|
|
||||||
local f1 = function() return Object.includes(Object, primitive) end
|
|
||||||
local f2 = function() return Object.includes(primitive, o) end
|
|
||||||
local f3 = function() return Object.includes(primitive, primitive) end
|
|
||||||
|
|
||||||
|
|
||||||
describe('don\'t throw errors', function()
|
|
||||||
it('includes(Object, '.. theType ..')', function()
|
|
||||||
assert.not_error(f1)
|
|
||||||
end)
|
|
||||||
it('includes(' .. theType .. ', Object:new())', function()
|
|
||||||
assert.not_error(f2)
|
|
||||||
end)
|
|
||||||
it('includes(' .. theType .. ',' .. theType ..')', function()
|
|
||||||
assert.not_error(f3)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('make includes return false', function()
|
|
||||||
assert.is_false(f1())
|
|
||||||
assert.is_false(f2())
|
|
||||||
assert.is_false(f3())
|
|
||||||
end)
|
|
||||||
|
|
||||||
end)
|
|
||||||
end -- for
|
|
||||||
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe('A class', function()
|
|
||||||
|
|
||||||
local Class1 = class('Class1')
|
|
||||||
local Class2 = class('Class2', Class1)
|
|
||||||
local Class3 = class('Class3', Class2)
|
|
||||||
local UnrelatedClass = class('Unrelated')
|
|
||||||
|
|
||||||
local hasFoo = { foo=function() return 'foo' end }
|
|
||||||
Class1:include(hasFoo)
|
|
||||||
|
|
||||||
it('returns true if it includes a mixin', function()
|
|
||||||
assert.is_true(Class1:includes(hasFoo))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('returns true if its superclass includes a mixin', function()
|
|
||||||
assert.is_true(Class2:includes(hasFoo))
|
|
||||||
assert.is_true(Class3:includes(hasFoo))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('returns false otherwise', function()
|
|
||||||
assert.is_false(UnrelatedClass:includes(hasFoo))
|
|
||||||
end)
|
|
||||||
|
|
||||||
end)
|
|
||||||
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user