`before()` is run before executing any of the `targets`
defined below.

This is where we can validate user input, configure default
scope variables, get extra dependencies, and so on.

@param  {Object} scope
@param  {Function} cb    [callback]
546478
function (scope, cb) {

    // scope.args are the raw command line arguments.
    //
    // e.g. if someone runs:
    // $ sails generate controller-ts user find create update
    // then `scope.args` would be `['user', 'find', 'create', 'update']`
    if (!scope.args[0]) {
      return cb( 'Usage: sails generate controller-ts <controllername>' );
    }

    if (!scope.rootPath) {
      return cb( INVALID_SCOPE_VARIABLE('rootPath') );
    }

    // Ensure that the command is ran from root.
    if (!isValidRoot(scope.rootPath)) {
      return cb( INVALID_ROOT_PATH() );
    }

    // Ensure that the name is valid
    if (!isValidName(scope.args[0])) {
      return cb( INVALID_NAME() );
    }

    checkMissingDefinitions(scope.rootPath);
    
    // Attach defaults
    _.defaults(scope, {
      createdAt: new Date()
    });

    // Limit controller name correctly.
    var capitalizedName = capitalize(scope.args[0]);
    scope.controllerName = capitalizedName + 'Controller';
    // Pluralize item.
    scope.modelName = pluralize(capitalizedName);

    if (doesControllerExist(scope.rootPath, scope.controllerName)) {
      return cb( ALREADY_EXISTS(scope.controllerName) );
    }

    // Decide the output filename for use in targets below:
    scope.filename = '/api/controllers/' + scope.controllerName + '.ts';

    cb();
  }
1250511
function (scope, cb) {

    // scope.args are the raw command line arguments.
    //
    // e.g. if someone runs:
    // $ sails generate sailsstripe user find create update
    // then `scope.args` would be `['user', 'find', 'create', 'update']`
    /*
    if (!scope.args[0]) {
      return cb( new Error('Please provide a name for this sails-stripe.') );
    }
    */

    // scope.rootPath is the base path for this generator
    //
    // e.g. if this generator specified the target:
    // './Foobar.md': { copy: 'Foobar.md' }
    //
    // And someone ran this generator from `/Users/dbowie/sailsStuff`,
    // then `/Users/dbowie/sailsStuff/Foobar.md` would be created.
    
    if (!scope.rootPath) {
      return cb( INVALID_SCOPE_VARIABLE('rootPath') );
    }

    // Attach defaults
    _.defaults(scope, {
      createdAt: new Date()
    });

    // Decide the output filename for use in targets below:
    //scope.filename = scope.args[0];

    // Add other stuff to the scope for use in our templates:
    scope.whatIsThis = 'sails-stripe created at '+scope.createdAt+', it just saved you a ton of time, how about buying @ScottBWyatt a beer?';

    // When finished, we trigger a callback with no error
    // to begin generating files/folders as specified by
    // the `targets` below.
    cb();
  }
520909
function setScope (scope) {
    // throw error if attempting operation on complete audit record
    assert.ok(!this.complete, 'cannot setScope on complete audit record')
    // set scope value
    this.scope = scope
    // allow request is complete
    this.complete = true
    // debug
    debug(this)
    // return set value
    return this.scope
}
954447
void processScope(Scope scope) {
    boolean shouldAddToBlockStack = !scope.isHoistScope();
    this.narrowScope = scope;
    if (shouldAddToBlockStack) {
      blockStack.add(new BasicBlock(null, scope.getRootNode()));
    }
    (new NodeTraversal(compiler, this, scopeCreator)).traverseAtScope(scope);
    if (shouldAddToBlockStack) {
      pop(blockStack);
    }
    this.narrowScope = null;
  }
245989
def execute_until_in_scope(
    expr, scope, aggcontext=None, clients=None, post_execute_=None, **kwargs
):
    
    # these should never be None
    assert aggcontext is not None, 'aggcontext is None'
    assert clients is not None, 'clients is None'
    assert post_execute_ is not None, 'post_execute_ is None'

    # base case: our op has been computed (or is a leaf data node), so
    # return the corresponding value
    op = expr.op()
    if op in scope:
        return scope[op]

    new_scope = execute_bottom_up(
        expr,
        scope,
        aggcontext=aggcontext,
        post_execute_=post_execute_,
        clients=clients,
        **kwargs,
    )
    new_scope = toolz.merge(
        new_scope, pre_execute(op, *clients, scope=scope, **kwargs)
    )
    return execute_until_in_scope(
        expr,
        new_scope,
        aggcontext=aggcontext,
        clients=clients,
        post_execute_=post_execute_,
        **kwargs,
    )
879984
public function beforeScenario(BeforeScenarioScope $scope)
    {
        $environment = $scope->getEnvironment();

        if ($environment instanceof InitializedContextEnvironment) {
            $this->eventsContext = $environment->getContext(EventsContext::class);
        }
    }
476607
function executeCallback(cb, arg) {
    var r = cb(arg)
    if(r !== undefined && !isLikeAFuture(r) )
        throw Error("Value returned from then or catch ("+r+") is *not* a Future. Callback: "+cb.toString())

    return r
}
352569
function (cb) {
            if (cb) {
                if (isPromise(cb)) {
                    cb = cb.callback;
                }
                if (this.__fired && this.__results) {
                    this.__callNextTick(cb, this.__results);
                } else {
                    this.__cbs.push(cb);
                }
            }
            return this;
        }
1091920
function workFn() {
      var modules = currentSpec.$modules || [];

      modules.unshift('ngMock');
      modules.unshift('ng');
      var injector = currentSpec.$injector;
      if (!injector) {
        injector = currentSpec.$injector = angular.injector(modules);
      }
      for(var i = 0, ii = blockFns.length; i < ii; i++) {
        try {
          /* jshint -W040 *//* Jasmine explicitly provides a `this` object when calling functions */
          injector.invoke(blockFns[i] || angular.noop, this);
          /* jshint +W040 */
        } catch (e) {
          if(e.stack && errorForStack) e.stack +=  '\n' + errorForStack.stack;
          throw e;
        } finally {
          errorForStack = null;
        }
      }
    }
401956
function before(ctx) {
  var fn = lookup(ctx.operation, 'middleware', 'before');
  var prefix = describe(ctx);

  if (fn) {
    return fn(ctx);
  } else {
    debug(prefix + 'before middleware disabled (not defined)');
  }
}
1238602
public function onceTo($scope, callable $callback)
    {
        $mainScope = $this->scope;

        $this->scope = $scope;

        $result = $callback();

        $this->scope = $mainScope;

        return $result;
    }
114844
function toHaveBeenDone() {
  var getErrorMsg = jasmine.formatErrorMsg('<toHaveBeenDone>', 'expect(<scopeObj>).toHaveBeenDone()');
  var pp = jasmine.pp;

  return {
    compare: function (actual) {
      var result = { pass: false };

      if (!actual.isDone) {
        throw new Error(getErrorMsg('Expected a nock scope, but got ' + pp(actual) + '.'));
      }

      if (actual.basePath) {
        var key = actual.interceptors[0]._key;
        if (actual.isDone()) {
          result.pass = true;
          result.message = 'Expected nock scope expectation "' + key + '" not to have been done but it was.';
        } else {
          result.message = 'Expected nock scope expectation "' + key + '" to have been done but it was never done.';
        }

        return result;
      }

      if (actual.isDone()) {
        result.pass = true;
        result.message = 'Expected nock expectations to have not been done but they were done.';
      } else {
        result.message = 'Expected nock expectations to have been done but they were never done.';
      }

      return result;
    }
  };
}
1237042
public function applyScopeToQuery($scope, $query)
    {
        if (is_string($scope)) {
            $scope = $this->getScope($scope);
        }

        if (!$scope->value) {
            return;
        }

        switch ($scope->type) {
            case 'date':
                if ($scope->value instanceof Carbon) {
                    $value = $scope->value;

                    /*
                     * Condition
                     */
                    if ($scopeConditions = $scope->conditions) {
                        $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                            ':filtered' => $value->format('Y-m-d'),
                            ':after'    => $value->format('Y-m-d H:i:s'),
                            ':before'   => $value->copy()->addDay()->addMinutes(-1)->format('Y-m-d H:i:s')
                        ])));
                    }
                    /*
                     * Scope
                     */
                    elseif ($scopeMethod = $scope->scope) {
                        $query->$scopeMethod($value);
                    }
                }

                break;

            case 'daterange':
                if (is_array($scope->value) && count($scope->value) > 1) {
                    list($after, $before) = array_values($scope->value);

                    if ($after && $after instanceof Carbon && $before && $before instanceof Carbon) {

                        /*
                         * Condition
                         */
                        if ($scopeConditions = $scope->conditions) {
                            $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                                ':afterDate'  => $after->format('Y-m-d'),
                                ':after'      => $after->format('Y-m-d H:i:s'),
                                ':beforeDate' => $before->format('Y-m-d'),
                                ':before'     => $before->format('Y-m-d H:i:s')
                            ])));
                        }
                        /*
                         * Scope
                         */
                        elseif ($scopeMethod = $scope->scope) {
                            $query->$scopeMethod($after, $before);
                        }
                    }
                }

                break;

            case 'number':
                if (is_numeric($scope->value)) {
                    /*
                     * Condition
                     */
                    if ($scopeConditions = $scope->conditions) {
                        $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                            ':filtered' => $scope->value,
                        ])));
                    }
                    /*
                     * Scope
                     */
                    elseif ($scopeMethod = $scope->scope) {
                        $query->$scopeMethod($scope->value);
                    }
                }

                break;

            case 'numberrange':
                if (is_array($scope->value) && count($scope->value) > 1) {
                    list($min, $max) = array_values($scope->value);

                    if ($min && $max) {

                        /*
                         * Condition
                         *
                         */
                        if ($scopeConditions = $scope->conditions) {
                            $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                                ':min'  => $min,
                                ':max'  => $max
                            ])));
                        }
                        /*
                         * Scope
                         */
                        elseif ($scopeMethod = $scope->scope) {
                            $query->$scopeMethod($min, $max);
                        }
                    }
                }

                break;

            case 'text':
                /*
                 * Condition
                 */
                if ($scopeConditions = $scope->conditions) {
                    $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                        ':value' => Db::getPdo()->quote($scope->value),
                    ])));
                }

                /*
                 * Scope
                 */
                elseif ($scopeMethod = $scope->scope) {
                    $query->$scopeMethod($scope->value);
                }

                break;

            default:
                $value = is_array($scope->value) ? array_keys($scope->value) : $scope->value;

                /*
                 * Condition
                 */
                if ($scopeConditions = $scope->conditions) {

                    /*
                     * Switch scope: multiple conditions, value either 1 or 2
                     */
                    if (is_array($scopeConditions)) {
                        $conditionNum = is_array($value) ? 0 : $value - 1;
                        list($scopeConditions) = array_slice($scopeConditions, $conditionNum);
                    }

                    if (is_array($value)) {
                        $filtered = implode(',', array_build($value, function ($key, $_value) {
                            return [$key, Db::getPdo()->quote($_value)];
                        }));
                    }
                    else {
                        $filtered = Db::getPdo()->quote($value);
                    }

                    $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [':filtered' => $filtered])));
                }
                /*
                 * Scope
                 */
                elseif ($scopeMethod = $scope->scope) {
                    $query->$scopeMethod($value);
                }

                break;
        }

        return $query;
    }
434653
function makeScope(prev, isCatch) {
    return {vars: Object.create(null), prev: prev, isCatch: isCatch};
  }
570145
public function gatherContexts(BeforeScenarioScope $scope) {
      $environment = $scope->getEnvironment();
      $this->mink = $environment->getContext('Starbug\Behat\Context\MinkContext');
  }
514002
function beforeList (controller, args, fields, title, form, links, defaultQueryArgs) {
    // get model from controller
    var model = controller.model
    // set limit
    var limit = args.limit || controller.defaultLimit
    var offset = args.offset || 0
    // set to true to show clear option for filters/sort
    var clear = false
    // set minimum limit to 2
    if (limit < 2) {
        limit = 2
    }
    // build arguments for query
    var query = {
        session: args.session,
    }
    // if query args are passed use them
    if (defined(defaultQueryArgs)) {
        _.merge(query, defaultQueryArgs)
    }
    // add order if set
    if (defined(args.orderColumn)) {
        query.order = [args.orderColumn]
        // if custom order is set add clear option
        clear = true
        // add direction if set
        if (defined(args.orderDirection)) {
            query.order.push(args.orderDirection)
        }
    }
    // add where if set
    if (defined(args.where)) {
        query.where = JSON.parse(args.where)
    }
    // included deleted records
    if (defined(args.deleted)) {
        // create where query if not set
        if (!defined(query.where)) {
            query.where = {}
        }
        // include deleted records - if argument is only then only deleted
        query.where.isDeleted = args.deleted === 'only'
            ? true: null
    }
    // add extra columns as query param options
    _.each(model.extraColumns, (spec, name) => {
        // if param is set in args add to where query
        if (typeof args[name] === 'string') {
            // create where query if not set
            if (!defined(query.where)) {
                query.where = {}
            }
            // if query is quoted then do exact match
            var queryArg = args[name].charAt(0) === '"' && args[name].charAt(args[name].length - 1) === '"'
                // strip leading and trailing quotes
                ? args[name].substr(1, args[name].length - 2)
                // add wildcards to string
                : `%${args[name]}%`
            // set like query
            query.where[name] = {like: queryArg}
            // if filter is set add clear option
            clear = true
            // and param to sort links
            _.each(fields, field => {
                if (field.orderAscUrl) {
                    field.orderAscUrl += '&'+name+'='+args[name]
                }
                if (field.orderDescUrl) {
                    field.orderDescUrl += '&'+name+'='+args[name]
                }
            })
        }
    })
    // if originalId set add to query
    if (args.originalId) {
        // create where query if not set
        if (!query.where) {
            query.where = {}
        }
        // set originalId in query
        query.where.originalId = {eq: args.originalId}
    }
    // do database query
    return model.query(query)
    // prepare args for primary method
    .then(result => {
        // remove session from query args for presentation
        delete query.session
        // fetch records
        return result.fetch(limit, offset)
        // resolve with result and record data
        .then(records => {
            // add actions to records
            _.each(records, record => {
                buildActions(controller, record)
            })
            // return data that will be merged into args for primary method
            return {
                clear: clear,
                fields: fields,
                form: form,
                links: links,
                query: query,
                records: records,
                result: {
                    length: result.length,
                },
                title: title,
            }
        })
    })
}
1100191
function MainCtrl($scope, $location) {

    $scope.select = function select(id) {
      $scope.selected = $scope.selected === id ? null : id;
      $location.path('/' + id);
    };

    $scope.examples = examples;
    $scope.select($location.path().substring(1) || examples[0].id);

  }