<commit_before># == Schema Information
#
# Table name: images
#
#  id         :integer          not null, primary key
#  site_id    :integer
#  image_uid  :string(255)
#  created_at :datetime
#  updated_at :datetime
#  idx        :integer          default(0)
#  crop_data  :text
#  image_site :string(255)
#  image_name :string(255)
#

class Image < ActiveRecord::Base

  # ------------------------------------------ Plugins

  dragonfly_accessor :image

  # ------------------------------------------ Attributes

  serialize :crop_data, Hash

  # ------------------------------------------ Associations

  belongs_to :site, :touch => true

  has_many :page_images
  has_many :pages, :through => :page_images

  # ------------------------------------------ Scopes

  scope :by_idx, -> { reorder('idx asc') }

  # ------------------------------------------ Callbacks

  after_create :create_idx

  after_save :cache_attrs

  def cache_attrs
    update_columns(
      :image_site => site.slug, 
      :image_name => self.image.meta['name']
    )
  end

  # ------------------------------------------ Instance Methods

  def to_param
    idx.to_s
  end

  def create_idx
    last_obj = self.site.images.by_idx.last
    idx = last_obj.idx + 1
    update_columns(:idx => idx)
  end

  def method_missing(method, *arguments, &block)
    begin
      super
    rescue
      crop_data.keys.include?(method.to_s) ? crop(method.to_s) : super
    end
  end

  def respond_to?(method, include_private = false)
    begin
      super
    rescue
      crop_data.keys.include?(method.to_s) ? true : false
    end
  end

  def crop(version)
    unless crop_data[version].blank?
      hash = crop_data[version].map { |k,v| {k => v.to_f} }.reduce(:merge)
      OpenStruct.new(hash)
    end
  end

  def url_things
    ['hello_world','beast'].join('/')
  end

end
<commit_msg>validation for image file types<commit_after># == Schema Information
#
# Table name: images
#
#  id         :integer          not null, primary key
#  site_id    :integer
#  image_uid  :string(255)
#  created_at :datetime
#  updated_at :datetime
#  idx        :integer          default(0)
#  crop_data  :text
#  image_site :string(255)
#  image_name :string(255)
#

class Image < ActiveRecord::Base

  # ------------------------------------------ Plugins

  dragonfly_accessor :image

  # ------------------------------------------ Attributes

  serialize :crop_data, Hash

  # ------------------------------------------ Associations

  belongs_to :site, :touch => true

  has_many :page_images
  has_many :pages, :through => :page_images

  # ------------------------------------------ Scopes

  scope :by_idx, -> { reorder('idx asc') }

  # ------------------------------------------ Callbacks

  after_create :create_idx

  after_save :cache_attrs

  def cache_attrs
    update_columns(
      :image_site => site.slug, 
      :image_name => self.image.meta['name']
    )
  end

  # ------------------------------------------ Validations

  validates_property(
    :format, 
    :of => :image, 
    :in => ['jpeg', 'jpg', 'png', 'gif']
  )

  # ------------------------------------------ Instance Methods

  def to_param
    idx.to_s
  end

  def create_idx
    last_obj = self.site.images.by_idx.last
    idx = last_obj.idx + 1
    update_columns(:idx => idx)
  end

  def method_missing(method, *arguments, &block)
    begin
      super
    rescue
      crop_data.keys.include?(method.to_s) ? crop(method.to_s) : super
    end
  end

  def respond_to?(method, include_private = false)
    begin
      super
    rescue
      crop_data.keys.include?(method.to_s) ? true : false
    end
  end

  def crop(version)
    unless crop_data[version].blank?
      hash = crop_data[version].map { |k,v| {k => v.to_f} }.reduce(:merge)
      OpenStruct.new(hash)
    end
  end

  def url_things
    ['hello_world','beast'].join('/')
  end

end

{'fraction_non_alphanumeric': 0.2365038560411311, 'fraction_numerical': 0.005655526992287918, 'mean_word_length': 1.683448275862069, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '765037', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1188, 'n_words': 266}