Add support for `GEM_HOME` and `GEM_PATH`

This should fix #657. Unfortunately I’m not versed in PHP unit testing proces (I’m front-end developer primarily) so I hope this won’t create any problems in merging this pull request. Please fell free to revise this pull request with any additions or fixes.
Fixed here, and for `BaseNodeFilter` in #663