<commit_before>class Cms::File < ActiveRecord::Base
  include Cms::Base

  IMAGE_MIMETYPES = %w(gif jpeg pjpeg png tiff).collect{|subtype| "image/#{subtype}"}

  cms_is_categorized

  attr_accessor :dimensions

  has_attached_file :file, ComfortableMexicanSofa.config.upload_file_options.merge(
      # dimensions accessor needs to be set before file assignment for this to work
      :styles => lambda { |f|
        if f.respond_to?(:instance) && f.instance.respond_to?(:dimensions)
          (f.instance.dimensions.blank?? { } : { :original => f.instance.dimensions }).merge(
              :cms_thumb => '80x60#',
              :resized => '640x480#',
              :mini => '40x30#'
          )
        end
      },
      :path => ':rails_root/public/assets/sites/:site_id/:class/:id/:basename.:style.:extension',
      :url => '/assets/sites/:site_id/:class/:id/:basename.:style.:extension'
  )
  before_post_process :is_image?

  # -- Relationships --------------------------------------------------------
  belongs_to :site
  belongs_to :block

  belongs_to :group,
             inverse_of: :files

  # -- Validations ----------------------------------------------------------
  validates :site_id,
            :presence   => true
  validates_attachment_presence :file
  validates :file_file_name,
            :uniqueness => {:scope => :site_id}

  validates_inclusion_of :site_id,<commit_msg>preserve geometry for resized images<commit_after>class Cms::File < ActiveRecord::Base
  include Cms::Base

  IMAGE_MIMETYPES = %w(gif jpeg pjpeg png tiff).collect{|subtype| "image/#{subtype}"}

  cms_is_categorized

  attr_accessor :dimensions

  has_attached_file :file, ComfortableMexicanSofa.config.upload_file_options.merge(
      # dimensions accessor needs to be set before file assignment for this to work
      :styles => lambda { |f|
        if f.respond_to?(:instance) && f.instance.respond_to?(:dimensions)
          (f.instance.dimensions.blank?? { } : { :original => f.instance.dimensions }).merge(
              :cms_thumb => '80x60#',
              :resized => '640x480',
              :mini => '40x30#'
          )
        end
      },
      :path => ':rails_root/public/assets/sites/:site_id/:class/:id/:basename.:style.:extension',
      :url => '/assets/sites/:site_id/:class/:id/:basename.:style.:extension'
  )
  before_post_process :is_image?

  # -- Relationships --------------------------------------------------------
  belongs_to :site
  belongs_to :block

  belongs_to :group,
             inverse_of: :files

  # -- Validations ----------------------------------------------------------
  validates :site_id,
            :presence   => true
  validates_attachment_presence :file
  validates :file_file_name,
            :uniqueness => {:scope => :site_id}

  validates_inclusion_of :site_id,
{'fraction_non_alphanumeric': 0.20035460992907803, 'fraction_numerical': 0.009929078014184398, 'mean_word_length': 2.1875706214689266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '2320846', 'n_tokens_mistral': 894, 'n_tokens_neox': 858, 'n_words': 157}