/** api: module = process */

/** api: synopsis
 *  Process related functionality.
 */

/** api: summary
 *  The :mod:`process` module provides a constructor for Process objects.
 *
 *  .. code-block:: javascript
 *  
 *      js> var PROCESS = require("geoscript/process");
 */

var UTIL = require("./util");
var Registry = require("./registry").Registry;
var Factory = require("./factory").Factory;
var Field = require("./feature").Field;
var apply = require("./util").apply;
var defer = require("ringo/promise").defer;

/** api: class = Process */
var Process = exports.Process = UTIL.extend(Object, {

    /** api: config[title]
     *  ``String``
     *  Title for the process.
     */
    /** api: property[title]
     *  ``String``
     *  Title for the process.
     */
    title: null,

    /** api: config[description]
     *  ``String``
     *  Full description of the process, including all input and output fields.
     */
    /** api: property[description]
     *  ``String``
     *  Full description of the process, including all input and output fields.
     */
    description: null,

    /** api: config[inputs]
     *  ``Array``
     *  List of input fields for the process.
     */
    /** api: property[inputs]
     *  ``Array``
     *  List of input fields for the process.
     */
    inputs: null,

    /** api: config[outputs]
     *  ``Array``
     *  List of output fields for the process.
     */
    /** api: property[outputs]
     *  ``Array``
     *  List of output fields for the process.
     */
    outputs: null,

    /** api: config[runner]
     *  ``Function``
     *  The function to be executed when running the process.
     */
    runner: null,

    /** api: constructor
     *  .. class:: Process
     *
     *      :arg config: `Object` Process configuration.
     *
     */
    constructor: function Process(config) {
        if (config) {
            // apply all config properties
            apply(this, config);
            // configure inputs
            this.inputs = (this.inputs || []).map(function(field) {
                return (field instanceof Field) ? field : new Field(field);
            });
            // configure outputs
            this.outputs = (this.outputs || []).map(function(field) {
                return (field instanceof Field) ? field : new Field(field);
            });
        }        
    },
    
    /** api: method[run]
     *  :arg values: ``Array`` List of input values.
     *  :returns: ``Object``  Returns a promise object with ``then`` and 
     *      ``wait`` methods.
     *
     *  Run the process.
     */
    run: function(values) {
        var response = defer();
        var promise = response.promise;
        function callback(outputs) {
            response.resolve(outputs);
        }
        function errback() {
            // set isError true
            response.resolve(Array.slice(arguments).concat(true));
        }
        this.runner(values, callback, errback);
        return promise;
    }
    
});

var callable = exports.callable = function(config) {
    var process = new Process(config);
    return function() {
        return process.run.apply(process, arguments);
    };
};

@@ -2613,18 +2613,12 @@
 ion(
-values
 ) %7B%0A
+
     
@@ -2657,40 +2657,62 @@
     
-var promise = response.promise;%0A
+this.runner(%0A            Array.slice(arguments), %0A    
     
@@ -2737,19 +2737,16 @@
 ack(
-outputs
 ) %7B%0A
+    
     
@@ -2774,16 +2774,31 @@
 lve(
-outpu
+Array.slice(argumen
 ts)
+)
 ;%0A  
@@ -2795,34 +2795,43 @@
 ents));%0A        
+  
-%7D%0A
+  %7D,%0A    
         function
@@ -2835,32 +2835,36 @@
 ion errback() %7B%0A
+    
             // s
@@ -2883,32 +2883,36 @@
 rue%0A            
+    
 response.resolve
@@ -2938,24 +2938,21 @@
 nts)
-.concat(
+, 
 true)
-)
 ;%0A
+    
     
@@ -2969,45 +2969,8 @@
     
-this.runner(values, callback, errback
 );%0A 
@@ -2983,16 +2983,25 @@
  return 
+response.
 promise;

Clean up run method.