Skip to content

Commit

Permalink
- documented "private" attributes
Browse files Browse the repository at this point in the history
- implemented/tested custom getter/setter names
  • Loading branch information
canonic-epicure committed Feb 19, 2010
1 parent cbfa206 commit 116d61e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/Joose/Managed/Attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Joose.Managed.Attribute = new Joose.Managed.Class('Joose.Managed.Attribute', {

if (this.isPrivate && !isPrivate) this.name = '__' + this.name

this.setterName = this.getSetterName()
this.getterName = this.getGetterName()
this.setterName = this.setterName || this.getSetterName()
this.getterName = this.getterName || this.getGetterName()
},


Expand Down
35 changes: 35 additions & 0 deletions lib/Joose/Manual/Attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,41 @@ There is a caveat worth mentioning in regards to what "required" actually means.
Basically, all it says is that this attribute (`username`) must be provided to the constructor. It does not say anything about its value, so it could be 'null' or 'undefined'.
Custom getter/setter names
--------------------------
You can specify arbitrary names for getter and setter methods names with `getterName/setterName" options:
has : {
username : {
is : 'rw',
init : 'root',
getterName : 'getUser',
setterName : 'setUser'
}
}
"Private" attributes
--------------------
Joose also allows you to somewhat imitate the "private" attributes with the `isPrivate` option:
has : {
username : {
is : 'rw',
init : 'root',
isPrivate : true
}
}
This option encumber the name of attribute and it will become available only through calls to getter/setter. Direct access to the attribute, like `this.username` will be meaningless -
at the later time, getter will retrive the attribute value from another key. Of course, this is only imitation, getter/setter methods are still available publicly.
Custom Metaclass
--------------------
Expand Down
4 changes: 2 additions & 2 deletions lib/Task/Joose/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2472,8 +2472,8 @@ Joose.Managed.Attribute = new Joose.Managed.Class('Joose.Managed.Attribute', {

if (this.isPrivate && !isPrivate) this.name = '__' + this.name

this.setterName = this.getSetterName()
this.getterName = this.getGetterName()
this.setterName = this.setterName || this.getSetterName()
this.getterName = this.getterName || this.getGetterName()
},


Expand Down
32 changes: 31 additions & 1 deletion t/051_advanced_attribute.t.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
StartTest(function (t) {

t.plan(34)
t.plan(38)


//==================================================================================================================================================================================
Expand Down Expand Up @@ -191,5 +191,35 @@ StartTest(function (t) {
testClass2.setRes1('newvalue1')
t.ok(testClass2.getRes1() == 'newvalue1', '.. and setter')



//==================================================================================================================================================================================
t.diag("Custom setter/getter names")

Class('TestClass3', {
has : {
res : {
is : 'rw',
init : 'advanced3',

getterName : 'GETRES',
setterName : 'SETRES'
}
}
})

t.ok(TestClass3.meta.hasMethod('GETRES') && TestClass3.meta.hasMethod('SETRES'), 'Custom getter/setter were added')


var testClass3 = new TestClass3()

t.ok(testClass3.res == 'advanced3', 'Attribute was initialized correctly')

t.ok(testClass3.GETRES() == 'advanced3', 'Customized getter works correctly')


testClass3.SETRES('custom')

t.ok(testClass3.GETRES() == 'custom', 'Customized setter works correctly')
})

2 changes: 1 addition & 1 deletion t/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Ext.extend = JooseX.Bridge.Ext.my.extend;
</script>

<script type="text/javascript" src="/jsan/Task/ExtJS/Debug/All.js"></script>
<script type="text/javascript" src="/jsan/Task/ExtJS/All.js"></script>

<!-- eof Ext bridge -->

Expand Down

0 comments on commit 116d61e

Please sign in to comment.