How to get Meteor.users collection on a Meteor package? - meteor

I'm developing a test frameword where I want to reset all collections on each run.
I'm having problems doing this with Meteor.users, since it's undefined on the package environment.
Is there any workaround to clean the Meteor.users collection from within a package?

The package load order and exported variables matter when it comes to symbol availability in packages.
In order to get a symbol created in a package, it has to be loaded prior to your package. This can be achieved by depending on it or on some other package that depends on it.
Examples of such symbols are methods added to the Meteor object, and this is what is happening in your case.
api.use('some-package'); // some-package is the desired package or depends on it
In order to get a symbol that is exported by a package, you should either directly depend on it, or depend on a package that implies this package (or explicitly exports the symbol on its own as well).
api.use('some-package'); // some-package exports the symbol directly or by implying
You can make this dependency weak if you don't want the package to be added to the bundle if your package is the only one that depends on it (i.e, there are no other packages that strongly depend on it, and the user did not add it as a top-level dependency).
api.use(['some-package'], ['client', 'server'], {weak: true});
If you need to do something after all of the packages have loaded, you can do so with Meteor.startup():
Meteor.startup(function() {
//do stuff after all packages and code were loaded
});

You can put some 'reset logic' on users collection,
Meteor.users.allow({
remove:function() {
resetLogic(); });
please check http://docs.meteor.com/#/full/allow for the reference

Related

Overriding non-visible S3 method within namespace

First I have a package called DataBaseLayer and it has an S3 method called LoadFromTable(data_request). Second there is another package called RiskCalculator which determines several types of risks and does requests to the database by means of the package DataBaseLayer. Before "triggering" RiskCalculator (by means of an execute function defined in it) a connection to some schema of the database is set up and the method LoadFromTable will refer to that particular schema.
For some tests that I need to perform I have to switch schema depending on the value in data_request that enters LoadFromTable(data_request). Thus what I actually need is to insert a little check in LoadFromTable. As a note, currently there is only a default method implemented, i.e. LoadFromTable.default, and it would thus suffice even to only insert that check in that specific method.
My question is thus twofold:
1. Is there a general way to insert a piece of code before any LoadFromTable method is called, naively said: to insert a piece of code just before UseMethod("LoadFromTable", data_request) is "called".
2. If there is no such way, can we at least insert a piece of code just before LoadFromTable.default is called (for in my case that would now suffice).
As a final note, I can imagine you might say that the whole structure should be changed, and I agree, however, that is not an option for I am not the owner of these packages.
Thanks for your help.
It’s strongly discouraged, and fundamentally the wrong approach, to change code in loaded packages, so I won’t discuss it here (but I’ll mention that this is done via the assignInNamespace function).
But your case can be solved much easier: just override the LoadFromTable generic function in the RiskCalculator package as follows:
LoadFromTable = function (request) {
# TODO: perform your check here.
DataBaseLayer::LoadFromTable(request)
}
Now if you load your RiskCalculator package and call the function either explicitly (via RiskCalculator::LoadFromTable) or implicitly (via LoadFromTable after attaching the RiskCalculator package), your implementation will be called.
Try trace:
library(DataBaseLayer)
trace(LoadFromTable, quote(print("Hello")))
The library statement is important, even if you don't otherwise access that package yourself.

Using bitbake is it possible to have a different do_install for a package based on the target image?

We have a single MACHINE which we use to build two target images; foo-image and foobar-image. Both images consume the same version of a package, but we would like to add a change to the do_install task based on which image is built. So that the recipe file for the package looks something like this:
do_install (){
//Some work
}
do_install_append_foobar-image(){
//Some foobar work
}
Eventually when we do the build for the two images:
MACHINE=custom bitbake foo-image
MACHINE=custom bitbake foobar-image
The image for foobar will contain the installed package that has done the work in the appends task, but the image for foo will not.
Is there any way to do what I have outlined or what would be an alternative?
No, you can't perform different tasks in a recipe based on which image is being built. There might be a possibility of checking the image name in the do_install though I'm highly unsure.
What I'd do is the following:
In the recipe, add a 2nd package which includes the additional files (if that's what you want to do).
Have your 2nd image recipe include this 2nd package.
Another possibility, depending on if you can detect which image you have built, is to add a post_install-script, that does the modification for you. A third, maybe less good option would be to do changes in a ROOTFS_POSTPROCESS_COMMAND.
Which solution you choose, will depend on what kind of customization you want to.
After some deliberation we were probably thinking about this backwards. We probably want to inject separation at the MACHINE level. Since both will be separate products in the end this makes the most sense. Doing it this way will allow us to introduce changes to packages for that specific product.
Our build lines will become:
MACHINE=custom1 bitbake foo-image
MACHINE=custom2 bitbake foobar-image
And our install task for the package can be:
do_install (){
//Some work
}
do_install_append_custom2(){
//Some more work
}

Meteor: Replace deanius:promise with okgrow:promise

my app was using deaunius:promise package for promises, now it is deprecated, and I have to translate all my promises to the syntax of okfrow:promise package, I was trying to understand how to create meteor Promises with that package and how to translate my current Promises to the new package but Im not sure how to do it in the proper way, it is quite different for me...
This is one example of a promise I used to write with deanius:promise
Meteor.promise('sendSubmission', null, submission)
.then( (result) ->
FlashMessages.sendSuccess "Successfully Finished the Test"
Router.go 'submissionView', _id: result.submissionId
).catch (error) ->
FlashMessages.sendError error.reason
Router.go 'takeTest', slug: currentTest.slug
How to write the above promise using okgrow:promise package? the examples they provide are not helpful at all for me. Thanks for your help
my app was using deaunius:promise package for promises, now it is deprecated
That wording seems to be unfortunate. Instead of being "deprecated", I'd have said "moved" - nothing really changed but the repository; it's still maintained by the same contributor. The code is just a fork, much of it is probably still the same.
I have to translate all my promises to the syntax of okfrow:promise package
No. The API has not changed a bit. All you would need to do is update the name of your dependency.

Meteor api.exports export undefined instead of function

I write a package wrapper for Meteorjs.
package.js have this line:
api.addFiles('my-package.js', 'client');
that successfully adds global property MyPackage to window object.
MyPackage property is a function.
If I add api.export(['MyPackage'], 'client'); though, MyPackage on window object becomes undefined instead. Any hints?
related to https://github.com/meteor/meteor/issues/4105
It is work as intended at the moment, as was explained by meteor team.
Reason was I was using this to initialize and assign lib variables, but you don't permitted to do this and assign like MyLib = {} (globally without any objects) instead.

Qt Installer Framework - How to customise?

I've managed to successfully create an ‘AdminProgram’ which is used to build the installer for my main project. It creates required configs/packages in file system correctly, updates all .xml files and copies all required elements into the correct places before building the installer, which is pretty great.
However, I am now looking to customize my installer to do a little more so that it is able to install a few drivers into the windows registry and at a later date remove existing installs before proceeding with a new one. I have studied the ‘instructions’ ( http://doc-snapshot.qt-project.org/qtifw-1.4/scripting.html#predefined-variables) for some time now and have been unable to quite grasp how exactly these Custom Operations are implemented (where the example code is supposed to be written, how the overridden operations are accessed etc.).
I find that the instruction are a little ambiguous for a programmer as inexperienced as myself and would very much appreciate some help from anyone who can give it?
In order to set entries in the registry you need to add GlobalConfig operations in your component script.
Overload the method Component.prototype.createOperations and add additional commands such as:
function Component() {
'use strict';
}
Component.prototype.createOperations = function () {
'use strict';
// call default implementation
component.createOperations();
component.addOperation("GlobalConfig",
"HKEY_CURRENT_USER\\Software\\#Publisher#\\#ProductName#\\entry",
"key",
"value");
}
The list of operations available are here

Resources