<commit_before><?php
namespace BenAllfree\LaravelStaplerImages;

use Codesleeve\Stapler\ORM\StaplerableInterface;
use Codesleeve\Stapler\ORM\EloquentTrait;

class Image  extends \Eloquent implements StaplerableInterface 
{
  use EloquentTrait;

  public static function from_url($url)
  {
    $i = new Image();
    $i->url = $url;
    $i->image = $url;
    $i->save();
    return $i;
  }
  
  public function __construct(array $attributes = array()) {
      $this->hasAttachedFile('image', [
          'styles' => self::styles()
      ]);

      parent::__construct($attributes);
  }
  
  public function should_reprocess()
  {
    return $this->sizes_md5 != self::style_md5();
  }
  
  public static function style_md5()
  {
    return md5(json_encode(self::styles()));
  }
  
  public static function styles()
  {
    $styles = \Config::get('laravel-stapler-images::config.sizes');
    if(!$styles || count($styles)==0)
    {
      throw new \Exception("No sizes defined for Image class. Are you sure you registered the service provider?");
    }
    return $styles;
  }
}

Image::saving(function($obj) {
  $obj->sizes_md5 = Image::style_md5();
});<commit_msg>Reuse records with identical URL<commit_after><?php
namespace BenAllfree\LaravelStaplerImages;

use Codesleeve\Stapler\ORM\StaplerableInterface;
use Codesleeve\Stapler\ORM\EloquentTrait;

class Image  extends \Eloquent implements StaplerableInterface 
{
  use EloquentTrait;

  public static function from_url($url)
  {
    $i = Image::whereUrl($url)->first();
    if($i) return $i;
    $i = new Image();
    $i->url = $url;
    $i->image = $url;
    $i->save();
    return $i;
  }
  
  public function __construct(array $attributes = array()) {
      $this->hasAttachedFile('image', [
          'styles' => self::styles()
      ]);

      parent::__construct($attributes);
  }
  
  public function should_reprocess()
  {
    return $this->sizes_md5 != self::style_md5();
  }
  
  public static function style_md5()
  {
    return md5(json_encode(self::styles()));
  }
  
  public static function styles()
  {
    $styles = \Config::get('laravel-stapler-images::config.sizes');
    if(!$styles || count($styles)==0)
    {
      throw new \Exception("No sizes defined for Image class. Are you sure you registered the service provider?");
    }
    return $styles;
  }
}

Image::saving(function($obj) {
  $obj->sizes_md5 = Image::style_md5();
});
{'fraction_non_alphanumeric': 0.1483790523690773, 'fraction_numerical': 0.005818786367414797, 'mean_word_length': 3.4906716417910446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '5619878', 'n_tokens_mistral': 826, 'n_tokens_neox': 809, 'n_words': 167}