Use this to decorate methods that expect a model.
558442
def model(method):
        """"""
        def wrapper(self, *args, **kwargs):
            if self.__model__ is None:
                raise ValidationError(
                    'You cannot perform CRUD operations without selecting a '
                    'model first.',
                )
            return method(self, *args, **kwargs)
        return wrapper
70138
function addMethod(key) {
  Cacher.prototype[key] = function() {
    if (!this.md) {
      return Promise.reject(new Error('Model not set'));
    }
    this.method = key;
    return this.run.apply(this, arguments);
  };
}
531999
def patch_constructor(model):
    
    old_init = model.__init__

    def new_init(self, *args, **kwargs):
        self._mt_init = True
        populate_translation_fields(self.__class__, kwargs)
        for key, val in list(kwargs.items()):
            new_key = rewrite_lookup_key(model, key)
            # Old key is intentionally left in case old_init wants to play with it
            kwargs.setdefault(new_key, val)
        old_init(self, *args, **kwargs)
    model.__init__ = new_init
31387
def handle
      return unless engine?
      return if decorators.empty?

      validate_decorators!
      validate_pattern_matching!

      engine.add_method_decorator(method_type, method_name, decorator)
      mark_pattern_matching_decorators
      method_reference.make_alias(target)
      redefine_method
    end
1106651
protected function ensureModel()
    {
        Yii::trace('Model ensuring', __METHOD__);

        if ($this->multiple) {
            if (empty($this->model) || !is_array($this->model)) {
                $this->model = [$this->model];
            }
            foreach ($this->model as $model) {
                $this->ensureModelInternal($model);
            }

            return;
        }

        $this->ensureModelInternal($this->model);
    }
457656
def decorate(func, caller):
    
    evaldict = dict(_call_=caller, _func_=func)
    fun = FunctionMaker.create(
        func, "return _call_(_func_, %(shortsignature)s)",
        evaldict, __wrapped__=func)
    if hasattr(func, '__qualname__'):
        fun.__qualname__ = func.__qualname__
    return fun
18188
def decorate_init(init_decorator):
    

    def class_decorator(cls):
        cls.__init__ = init_decorator(cls.__init__)
        return cls

    return class_decorator
213257
def decorate(self, func, target, *anoop, **kwnoop):
        
        if target:
            self.target = target

        def decorated(decorated_self, *args, **kwargs):
            self.handle_target(
                request=decorated_self.request,
                controller_args=args,
                controller_kwargs=kwargs
            )
            return func(decorated_self, *args, **kwargs)

        return decorated
1041787
def get_model(method):
    """"""

    @wraps(method)
    def wrapper(migrator, model, *args, **kwargs):
        if isinstance(model, str):
            return method(migrator, migrator.orm[model], *args, **kwargs)
        return method(migrator, model, *args, **kwargs)
    return wrapper
1176170
function(model, options) {
      options = options ? _.clone(options) : {};
      var wait = options.wait;
      model = this._prepareModel(model, options);
      if (!model) return false;
      if (!wait) this.add(model, options);
      var collection = this;
      var success = options.success;
      options.success = function(m, resp, callbackOpts) {
        if (wait) collection.add(m, callbackOpts);
        if (success) success.call(callbackOpts.context, m, resp, callbackOpts);
      };
      model.save(null, options);
      return model;
    }
129035
def define(self, klass, name="default"):
        

        def decorate(func):
            @wraps(func)
            def wrapped(*args, **kwargs):
                return func(*args, **kwargs)

            self.register(klass, func, name=name)

            return wrapped

        return decorate
1058586
function setDefaultMethods(modelObj) {
    /* This will attach the .data(key, _val) method, that works as a virtual getter/setter.*/
    const dataKey = Symbol("data");
    modelObj.method(function data(key, _val) {
      if (typeof this[dataKey] === 'undefined') this[dataKey] = {};
      if (typeof key !== 'string' || !key) return null;
      if (typeof _val === 'undefined') return (typeof this[dataKey][key] === 'undefined' ? null : this[dataKey][key]);
      this[dataKey][key] = _val;
      return this;
    });
  }
1057926
def model_set(method_name):
    

    def model_set(value, context, **_params):
        method = getattr(context["model"], method_name)
        return _set(method, context["key"], value, (), {})

    return model_set
544462
def model_get(method_name):
    

    def model_get(_value, context, **_params):
        method = getattr(context["model"], method_name)
        return _get(method, context["key"], (), {})

    return model_get
464940
function applyModelMethods (model, definition) {
	for (var i in definition.methods) {
		if (i === 'definition') {
			throw new Error('Invalid model definition provided. "definition" is a reserved word');
		}

		model.prototype[i] = definition.methods[i];
	}
}
185376
def add_method(self, pattern):
        """"""
        def wrap(f):
            def frozen_function(class_instance, f):
                def _(pattern, *args, **kwargs):
                    return f(class_instance, pattern, *args, **kwargs)

                return _

            self.functions.append((frozen_function(self, f), pattern))
            return f

        return wrap
194208
def decorate(self, fun):
        """"""
        @wraps(fun)
        def _decorated(*args, **kwargs):
            # Push the config, run the function and pop it afterwards.
            self.push_config()
            try:
                return fun(*args, **kwargs)
            finally:
                self.pop_config()
        return _decorated