# Regard

Sugar-interface to access multiple data sources.

## Example

```javascript
var Regard = require('regard');

var regard = Regard('fs', 'rest')
  .$('root', __dirname)
  .$('root/sample', 'sample.json')
  .$('mb', 'http://mockbin.com');

regard
  .mb('request').then(function (res) {
    return regard.root.sample('write', res.body);
  })
  .then(regard.root.sample())
  .then(console.log);
```

## API

### Constructor

#### Regard(`[connectors]`)

Create new _Regard_ instance. It can be initialized with connectors given in args.

##### Arguments

* `[connectors]` (...(_Function_|_string_)): Connectory factory or name of core connector.

##### Returns

(_Regard_): Returns the new Regard instance.

##### Throws

* Error when a connector is not a _Function_.
* Error when a string is not a core connector name.

#### Example

```javascript
var Regard = require('regard);

var regard = Regard(Regard.FsConnector, Regard.RestConnector);

// or
//var regard = Regard('fs', 'rest');
```api



### Methods

#### regard(`endpoint`, `[args]`)

Create _Promise_ which accomplish request with an _Endpoint_.

##### Arguments

* `endpoint` (_string_): _Endpoint_ name.
* `[args]` (..._Mixed_): Arguments passed to _beforeRequest()_ which is called before the connector _process()_.

##### Returns

(_Promise_): Returns a _Promise_ instance which accomplish request.

##### Throws

* Error when no _Endpoint_ corresponding to the given name.

#### regard.$(`name`, `[path]`, `[settings]`, `api`, `cb`)

Create new _Endpoint_.

##### Arguments

* `name` (_string_): _Endpoint_ name.
* `[path]` (_string_): _Endpoint_ path.
* `[settings]` (_Object_): _Endpoint_ settings.
* `[api]` (_Function_): Function used to override _connector.beforeProcess()_.
* `[cb]` (_Function_): Function used to override _connector.afterProcess()_.

##### Returns

(_Regard_): Returns the current _Regard_ instance.

##### Throws

* Error when no _Connector_ was found to handle requests of the new endpoint.

#### regard.$$(`name`, `[args]`)

Create new _Connector_.

##### Arguments

* `connector` (_Function_|_string_|_Function[]_|_string[]_): Connector factory or name of a core connector.
* `[args]` (..._Mixed_): Arguments passed to _connector.init()_.

##### Returns

(_Regard_): Returns the current _Regard_ instance.

##### Throws

* Error when a connector is not a _Function_.
* Error when a string is not a core connector name.
