Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

use function call as a scope parameter #1

Closed
tristanls opened this Issue Dec 13, 2012 · 3 comments

Comments

Projects
None yet
2 participants
Owner

tristanls commented Dec 13, 2012

Consider using functions to evaluate accepting an incoming message.

ex:

var scope = [ functionTester, function () { return ( Date().getDate() % 2 )? '@oddDayAccount' : null }, '@bob' ];

'@bob' would be converted to a function via scope[ 2 ] = lambda( scope[ 2 ] ) resulting in scope[ 2 ]() === '@bob'. (where function lambda( e ) { return function () { return e } );)

Then, given msgAccount is the account of incoming message:

var canAccept = scope.some( function ( e ) {
  var v =  e();
  return Array.isArray( v ) ? v.indexOf( msgAccount ) >= 0 : v == msgAccount;
});

So if canAccept == true then this message can be accepted by the caller.

@ghost ghost assigned tristanls Dec 13, 2012

Expanding upon this:

/* this example allows all messages from everyone */
[ true ] 
/* This example would allow messages from @someAdmin and if radius auth returned true) */
[ '@someAdmin', function(askingUserAccount) { return checkRadius(askingUserAccount);} ]
/* this would allow anyone who is authorized through any one of a number of sources based on time of day */
[ function (askingUserAccount) {return getAuth(askingUserAccount, Date.now())} ];

/* Overly checking for logins from every source possible */
/* Short circuits, so if the first returns true, it doesn't execute any others. */
function getAuth(user,atTime) { return getFromMySQL(user,atTime)||getFromMongoDB(user,atTime)||getFromLDAP(user,atTime)};


var canAccept = scope.some(
  function(e){
    return e===msgAccount||e===true
     ?true
     :('function' === typeof e
      ?!(!e(msgAccount)) // force a boolean result just in case it's undefined or null.
      :false
     )
  }
)

So if canAccept == true then this message can be accepted by the caller.

Owner

tristanls commented Dec 15, 2012

Discussion thread with more information on this issue: https://groups.google.com/d/topic/crosstalk-developers/LNlPsSor6-Q/discussion

Owner

tristanls commented Oct 6, 2014

Project is no longer in development.

@tristanls tristanls closed this Oct 6, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment