<commit_before><?php namespace Betawax\RoleModel;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Validator;

class RoleModel extends Model {
	
	/**
	 * Validation rules.
	 *
	 * @var array
	 */
	public static $rules = array();
	
	/**
	 * Validation errors.
	 *
	 * @var Illuminate\Support\MessageBag
	 */
	protected $errors;
	
	/**
	 * Validator instance.
	 *
	 * @var Illuminate\Validation\Validator
	 */
	protected $validator;
	
	/**
	 * Force save.
	 *
	 * @var bool
	 */
	protected $force = false;
	
	/**
	 * Share the Validator instance.
	 *
	 * @param  array  $attributes
	 * @param  Illuminate\Validation\Validator  $validator
	 * @return void
	 */
	public function __construct(array $attributes = array(), Validator $validator = null)
	{
		parent::__construct($attributes);
		
		$this->validator = $validator ? $validator : \App::make('validator');
	}
	
	/**
	 * Register event bindings.
	 *
	 * @return void
	 */
	public static function boot()
	{
		parent::boot();
		
		static::saving(function($model)
		{
			if ( ! $model->force) return $model->validate();
		});
	}
	
	/**
	 * Validate the model's attributes.
	 *
	 * @param  array  $rules
	 * @return bool
	 */
	public function validate(array $rules = array())
	{
		$rules = $rules ? $rules : static::$rules;
		$validator = $this->validator->make($this->attributes, $rules);
		
		if ($validator->fails())
		{
			$this->errors = $validator->errors();
			return false;
		}
		
		$this->errors = null;
		return true;
	}
	
	/**
	 * Get validation errors.
	 *
	 * @return Illuminate\Support\MessageBag
	 */
	public function errors()
	{
		return $this->errors;
	}
	
	/**
	 * Check if the model has validation errors.
	 *
	 * @return bool
	 */
	public function hasErrors()
	{
		return ! is_null($this->errors);
	}
	
	/**
	 * Force save the model to the database.
	 *
	 * @param  array  $options
	 * @return bool
	 */
	public function forceSave(array $options = array())
	{
		$this->force = true;
		return parent::save($options);
	}
	
}
<commit_msg>Reset the force flag on standard save<commit_after><?php namespace Betawax\RoleModel;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Validator;

class RoleModel extends Model {
	
	/**
	 * Validation rules.
	 *
	 * @var array
	 */
	public static $rules = array();
	
	/**
	 * Validation errors.
	 *
	 * @var Illuminate\Support\MessageBag
	 */
	protected $errors;
	
	/**
	 * Validator instance.
	 *
	 * @var Illuminate\Validation\Validator
	 */
	protected $validator;
	
	/**
	 * Force save.
	 *
	 * @var bool
	 */
	protected $force = false;
	
	/**
	 * Share the Validator instance.
	 *
	 * @param  array  $attributes
	 * @param  Illuminate\Validation\Validator  $validator
	 * @return void
	 */
	public function __construct(array $attributes = array(), Validator $validator = null)
	{
		parent::__construct($attributes);
		
		$this->validator = $validator ? $validator : \App::make('validator');
	}
	
	/**
	 * Register event bindings.
	 *
	 * @return void
	 */
	public static function boot()
	{
		parent::boot();
		
		static::saving(function($model)
		{
			if ( ! $model->force) return $model->validate();
		});
	}
	
	/**
	 * Validate the model's attributes.
	 *
	 * @param  array  $rules
	 * @return bool
	 */
	public function validate(array $rules = array())
	{
		$rules = $rules ? $rules : static::$rules;
		$validator = $this->validator->make($this->attributes, $rules);
		
		if ($validator->fails())
		{
			$this->errors = $validator->errors();
			return false;
		}
		
		$this->errors = null;
		return true;
	}
	
	/**
	 * Get validation errors.
	 *
	 * @return Illuminate\Support\MessageBag
	 */
	public function errors()
	{
		return $this->errors;
	}
	
	/**
	 * Check if the model has validation errors.
	 *
	 * @return bool
	 */
	public function hasErrors()
	{
		return ! is_null($this->errors);
	}
	
	/**
	 * Save the model to the database.
	 *
	 * @param  array  $options
	 * @return bool
	 */
	public function save(array $options = array())
	{
		$this->force = false;
		return parent::save($options);
	}
	
	/**
	 * Force save the model to the database.
	 *
	 * @param  array  $options
	 * @return bool
	 */
	public function forceSave(array $options = array())
	{
		$this->force = true;
		return parent::save($options);
	}
	
}

{'fraction_non_alphanumeric': 0.1525503041647169, 'fraction_numerical': 0.0, 'mean_word_length': 2.9473684210526314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '911924', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1342, 'n_words': 334}