coderly/ember-gdrive — pull request #25 by begedin (2014-12-26 13:05:16+00:00)
Title: Fixed issue with app config being inaccessible from "addon" folder

This fixes #24.

Apparently, there was some caching issue when implementing #22, because after a system restart, an error was being thrown in

* addon/lib/picker.js
* addon/lib/share-dialog.js

It turns out that for addons inside the "app" folder of the addon, relative paths such as
```
../config/environment
```
translate to
```
[appname]/config/environment
```
However, the exact same relative path used in a script placed inside the "addon" folder of the addon translates to
```
[addonname]/config/environment
```
Because of that, the above two libraries were throwing a file-not-found error.

The solution is to create an initializer which then either injects the required config properties via `app.register/app.inject`, or it stores it somewhere for us to access later.

Since we require these config properties from inside regular libraries, I decided to go with a "singleton" route. I've created `addon/lib/config.js`. This is a module that exports an instance of an `Ember.object`, so it acts as a singleton. `app/initializers/load-config` is an initializer that runs before the `simple-auth` initializer. It loads the config properties into our singleton, so all other scripts can easily access it leader.

However, this **requires another change inside storypad**.

This is how our initializer function looks like:
```
initialize: function(container, app) {
//get you setting off of the app instance
config.load(app.get('ember-gdrive'));
}
```
The `app` object contains all properties defined inside the `APP` object of `[appname]/config/environment.js` and this is the only thing that's really easily accessible from inside an ember-cli addon. Basically, the expected way for us to share settings with an addon in an ember-cli application is to put those settings inside the `APP` object.

`ember-cli-simple-auth` doesn't do this because they never make use of the addon folder, so everything they have is contained within the "app" folder. For them, relative paths work just as well, but for us, that has an unfortunate consequence of messing up the config/environment script a bit - `ember-gdrive` options are now in `ENV.APP`, while `simple-auth` options remain in `ENV`.

In my opinion, **we should look into somehow removing the `simple-auth` options from config/environment completely**. They are tied to the addon we're using simple-auth from, so they should be unchangeable anyway.

http://stackoverflow.com/a/25631098 explains part of this.