Perform an atomic prepend for a new resource
977853
def add_resource(self, resource):
        ''''''
        resource.validate()
        self.update(__raw__={
            '$push': {
                'resources': {
                    '$each': [resource.to_mongo()],
                    '$position': 0
                }
            }
        })
        self.reload()
        post_save.send(self.__class__, document=self,
                       resource_added=resource.id)
743763
def prepare(self):
        
        # Maybe the Brok is a old daemon one or was already prepared
        # if so, the data is already ok
        if hasattr(self, 'prepared') and not self.prepared:
            self.data = unserialize(self.data)
            if self.instance_id:
                self.data['instance_id'] = self.instance_id
        self.prepared = True
561284
function (context, callback) {

            var self = this,
                options = {},
                model,
                processor,
                isPatch = context.request.method === "PATCH",
                upsert = this.$resourceConfiguration.$.upsert,
                defaults;


            flow()
                .seq("collection", function (cb) {
                    self._findCollection(context, cb);
                })
                .seq(function (cb) {
                    model = this.vars.collection.createItem(self.$resourceId);
                    defaults = _.clone(model.$);
                    // check if model exists
                    if (upsert && !isPatch) {
                        cb();
                    } else {
                        model.fetch(null, cb);
                    }
                })
                .seq(function () {
                    if (!isPatch) {
                        model.clear();
                        model.set(defaults);
                    }

                    var payload = context.request.params;

                    processor = self.$restHandler.$restDataSource.getProcessorForModel(model);

                    model.set(processor.parse(model, payload || {}));

                    options.action = DataSource.ACTION.UPDATE;

                    // TODO: add hook to add session data like user id
                    if (upsert === true) {
                        options.upsert = true;
                        model.set(model.idField, model.factory.prototype.convertIdentifier(self.$resourceId));
                    }
                })
                .seq(function () {
                    self._generateAutoValues(model);
                })
                .seq(function (cb) {
                    self._validate(model, context, cb);
                })
                .seq(function (cb) {
                    self._beforeModelSave(model, context, cb);
                })
                .seq(function (cb) {
                    self._beforeModelUpdate(model, context, cb);
                })
                .seq(function (cb) {
                    model.validateAndSave(options, cb);
                })
                .seq(function (cb) {
                    self._afterModelUpdate(model, context, cb);
                })
                .exec(function (err, results) {
                    if (!err) {
                        // TODO: do correct invalidation
                        results.collection.invalidatePageCache();

                        self._fetchAllHrefsForModel(model, context);

                        // TODO: generate the location header
                        var body = JSON.stringify(processor.compose(model, null));

                        var response = context.response;
                        response.writeHead(200, "", {
                            'Content-Type': 'application/json'
                            // TODO : add updated date in head ???
//                            'Location': context.request.urlInfo.uri
                        });

                        response.write(body);
                        response.end();

                        callback(null);
                    } else {
                        if (!(err instanceof HttpError)) {
                            var statusCode = 400;
                            if (err === DataSource.ERROR.NOT_FOUND) {
                                statusCode = 404;
                            }
                            err = new HttpError(err, statusCode);
                        }
                        callback(err);
                    }
                });

        }
1031484
def before_update(self, context, current, resource):
        

        # Return if the budget data package fields have not been filled in
        if not self.are_budget_data_package_fields_filled_in(resource):
            return

        if resource.get('upload', '') == '':
            # If it isn't an upload we check if it's the same url
            if current['url'] == resource['url']:
                # Return if it's the same
                return
            else:
                self.data.load(resource['url'])
        else:
            self.data.load(resource['upload'].file)

        self.generate_budget_data_package(resource)
394501
def dynamic_resource(name, default, options = {})
      @static_resources ||= {}
      @transient_resources ||= {}
      if @load_event == :static ||
         (!@load_event && options[:adding])
        if options[:set]
          @static_resources[name] = default
        else
          @static_resources[name] ||= default
        end
      elsif @load_event == :transient
        if options[:set]
          @transient_resources[name] = default
        else
          @transient_resources[name] ||= default
        end
      else
        static = @static_resources[name] ||= default
        transient = @transient_resources[name] ||= default
        if static.respond_to?('+')
          static + transient
        else
          static.merge(transient)
        end
      end
    end
451541
def safe_prepend_to_file(relative_path, *args, **options, &block)
      prepend_to_file(relative_path, *args, **(options.merge(force: false)), &block)
    end
1111531
def pre_execute(self, execution, context):
        """"""
        path = self._fspath
        if path:
            path = path.format(
                benchmark=context.benchmark,
                api=execution['category'],
                **execution.get('metas', {})
            )
            if self.clean_path:
                shutil.rmtree(path, ignore_errors=True)
            if execution['metas']['file_mode'] == 'onefile':
                path = osp.dirname(path)
            if not osp.exists(path):
                os.makedirs(path)
553193
def insert(self, context):
	
		
		
		status_code, msg = self.__endpoint.post(
			"/resources/custom-resource",
			data={
				"id": self.__name,
				"restype": self.__restype,
				"factoryclass": self.__factclass,
				"property": props_value(self.__props)
			}
		)
		self.__available = True
620345
private void executeGlobalPreprocessing(List<JoinableResourceBundle> bundlesToBuild, boolean processBundleFlag,
			StopWatch stopWatch) {

		stopProcessIfNeeded();

		if (resourceTypePreprocessor != null) {
			if (stopWatch != null) {
				stopWatch.start("Global preprocessing");
			}
			GlobalPreprocessingContext ctx = new GlobalPreprocessingContext(config, resourceHandler, processBundleFlag);
			resourceTypePreprocessor.processBundles(ctx, bundles);

			// Update the list of bundle to rebuild if new bundles have been
			// detected as dirty in the global preprocessing phase
			List<JoinableResourceBundle> currentBundles = getBundlesToRebuild();
			for (JoinableResourceBundle b : currentBundles) {
				if (!bundlesToBuild.contains(b)) {
					bundlesToBuild.add(b);
				}
			}
			if (stopWatch != null) {
				stopWatch.stop();
			}
		}
	}
169279
static <T> Iterable<T> prepend(Collection<T> coll, Iterable<T> rest) {
        return (coll.size() == 0) ? rest : new CompoundIterable<T>(coll, rest);
    }
871230
void prePrepare(Transaction transaction)
                    throws ObjectManagerException
    {
        throw new InvalidStateException(this, InternalTransaction.stateTerminated, InternalTransaction.stateNames[InternalTransaction.stateTerminated]);
    }
1070949
function onInit(output) {
    return Promise(output)
    .then(prepareI18n)
    .then(prepareResources)
    .then(copyPluginAssets);
}
2411
def prepare(self, context):
		""""""
		if __debug__:
			log.debug("Assigning thread local request context.")
		
		self.local.context = context
992724
def insert(self, resource, doc_or_docs, **kwargs):
        """"""
        ids = []
        kwargs.update(self._es_args(resource))
        for doc in doc_or_docs:
            self._update_parent_args(resource, kwargs, doc)
            _id = doc.pop('_id', None)
            res = self.elastic(resource).index(body=doc, id=_id, **kwargs)
            doc.setdefault('_id', res.get('_id', _id))
            ids.append(doc.get('_id'))
        self._refresh_resource_index(resource)
        return ids
567483
@NonNull
    public ObservableAdapterBuilder<T> prepends(@Nullable Observable<? extends Collection<? extends T>> prepends) {
        mPrepends = prepends;
        return this;
    }
1366074
function injectBefore(replServer, method, beforeFn) {
  var _orig = replServer[method];
  replServer[method] = function() {
    var args = Array.prototype.slice.call(arguments);
    var callback = args.pop();
    beforeFn.apply(null, args.concat(function(err, res) {
      if (err || res) {
        callback(err, res);
      } else {
        _orig.apply(replServer, args.concat(callback));
      }
    }));
  };
  return replServer;
}
358276
public function prepend(): void
    {
        $script = $this->parseArgs(func_get_args());
        if ($script !== false) {
            array_unshift($this->members, $script);
        }
    }