$schema: http://json-schema.org/draft-04/schema#
id: assignment.yml
type: object
description:
  Use an assignment object to alter values for session/user attributes.  
  This same object is also used by the `temp:` key in labels to alter
  temporary variables that only last for the duration of the request/response cycle.

  Assignments are evaluated in order.  For example, if the first key
  you provide in the assignment object is `set:` and the second is `increment:`,
  values will first be assigned in `set:` and then `increment:` will assigned
  values next.  This is important to understand because assignments will
  cause values to mutate in that way.  If you need to perform an operation
  multiple times in a given assignment, you can instead provide an array
  of operation objects.
definitions:
  operation:
    $ref: operation.yml
  operations: &operations
    set:
      $ref: '#/definitions/operation'
      description: 
        Sets a value to an attribute name.
    increment:
      $ref: '#/definitions/operation'
      description:
        Increments an existing number value by the number value given.
        To decrement, just provide a negative number.  If there is no
        number value already assigned to the specified attribute,
        nothing happens.
    erase:
      $ref: '#/definitions/operation'
      description:
        Deletes both the key and value of the attribute specified.
        The provided value does nothing.
    append:
      $ref: '#/definitions/operation'
      description:
        If a specified attribute is an array, the provided value is
        appended.  If instead the initial value of the attribute is
        a string, the provided value will be appended to the string.
        When there is no initial value, the provided value is simply
        assigned to that attribute.
    prepend:
      $ref: '#/definitions/operation'
      description:
        Same as append, but prepends.  Adds value to the beginning of
        an object rather than at the end.
    multiply:
      $ref: '#/definitions/operation'
      description:
        Multiplies a number by the value provided.  Nothing happens if
        there is no initial number value.
    min:
      $ref: '#/definitions/operation'
      description:
        If there is an initial number value, and it is less than the
        number provided, it will be then re-assigned to that minimum
        number.  Else, the value stays the same.
    max:
      $ref: '#/definitions/operation'
      description:
        If there is an initial number value, and it is greater than the
        number provided, it will be then re-assigned to that maximum
        number.  Else, the value stays the same.
    date:
      $ref: '#/definitions/operation'
      description:
        Assigns a date to the attribute.  You can either provide an actual
        date object or a human readable date string(e.g. 'today', '2 hours from now').
    expression:
      $ref: '#/definitions/operation'
      description:
        Evaluates the given value as a CoffeeScript, providing the current
        attribute value as the variable `x`.  The return value of the 
        expression gets assigned to the attribute. 
    slot:
      $ref: '#/definitions/operation'
      description:
        Assigns a slot value from the current request to an attribute.

## Using YAML inheritence was the only way I could get this
## to work satisfactoraly, as `items:` can't reference 
## `properties:` for whatever stupid reason.
properties:
  <<: *operations
items:
  <<: *operations

