 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ###
 
-_ = require "lodash"
 uuid = require "node-uuid"
 asciify = require "asciify"
 connect = require "connect"

util = require "util"
fs = require "fs"

# A shorthand method for creating new instances of the objectables.
# This method is better than explicitly creating new objects, since
# it is shorter and has nicer syntax. Please use this, instead of
# directly creating new objectables. Refer to the later for info.
module.exports.objectable = (@objectable) ->
    detected = _.isFunction @objectable
    passed = -> @objectable.length is 0
    objectable = "The argument is not a function"
    wrapping = "The wrapper must not have arguments"
    throw new Error objectable unless detected
    throw new Error wrapping unless passed()
    return new Objectable @objectable

# A shorthand method for creating new instances of the executables.
# This method is better than explicitly creating new objects, since
# it is shorter and has nicer syntax. Please use this, instead of
# directly creating new executable. Refer to the later for info.
module.exports.executable = (@executable) ->
    detected = _.isFunction @executable
    executable = "The argument is not a function"
    throw new Error executable unless detected
    return new Executable @executable

# A class that represents a wrapped remote classes. It accepts the
# class wrapped in function and then stores it for later. Then when
# requested, it emits the class object source code as a string and if
# requested - optionally emits stringified application construct
# around it. This is used to remote create class objects on the site.
module.exports.Objectable = class Objectable extends events.EventEmitter

    # A public constructor that takes the wrapped class object for
    # an objectible object. Beware, when you are passing the class
    # definitin in here, remember that the definition is most likely
    # will be executed on a remote side, with differen environment.
    constructor: (@objectable) ->

    # Generation of string representation of the object instantiation
    # in JavaScript, so that it can be executed remotely on site. An

    # and a set of arguments that must be scalars or similar to them.
    # This method does not do any processing of args, inserts raws.
    unprocessed: (binder, parameters...) ->
        detected = _.isFunction @sourcing()
        executable = "No valid executable has been set"
        throw new Error executable unless detected
        parameters.unshift binder or "this"
        joined = parameters.join(", ").toString()
        stringified = @sourcing().toString()
        "(#{stringified}).apply(#{joined})"

    # Generation of string representation of the function invocation
