<commit_before>require 'active_model'

# This the module which makes any class behave like ActiveModel.
module MailForm
  module Shim
    def self.included(base)
      base.class_eval do
        extend ActiveModel::Naming
        extend ActiveModel::Translation
        extend ActiveModel::Callbacks
        include ActiveModel::Validations
        include ActiveModel::Conversion

        extend MailForm::Shim::ClassMethods
        define_model_callbacks :create
      end
    end

    module ClassMethods
      def i18n_scope
        :mail_form
      end
    end

    # Initialize assigning the parameters given as hash.
    def initialize(params={})
      params.each_pair do |attr, value|
        self.send(:"#{attr}=", value)
      end unless params.blank?
    end

    # Returns a hash of attributes, according to the attributes existent in
    # self.class.mail_attributes.
    def attributes
      self.class.mail_attributes.inject({}) do |hash, attr|
        hash[attr.to_s] = send(attr)
        hash
      end
    end

    # Always return true so when using form_for, the default method will be post.
    def new_record?
      true
    end

    # Always return nil so when using form_for, the default method will be post.
    def id
      nil
    end

    # Create just check validity, and if so, trigger callbacks.
    def create
      if valid?
        _run_create_callbacks { true }
      else
        false
      end
    end
    alias :save :create
  end
end<commit_msg>Should respond to persisted? as well<commit_after>require 'active_model'

# This the module which makes any class behave like ActiveModel.
module MailForm
  module Shim
    def self.included(base)
      base.class_eval do
        extend ActiveModel::Naming
        extend ActiveModel::Translation
        extend ActiveModel::Callbacks
        include ActiveModel::Validations
        include ActiveModel::Conversion

        extend MailForm::Shim::ClassMethods
        define_model_callbacks :create
      end
    end

    module ClassMethods
      def i18n_scope
        :mail_form
      end
    end

    # Initialize assigning the parameters given as hash.
    def initialize(params={})
      params.each_pair do |attr, value|
        self.send(:"#{attr}=", value)
      end unless params.blank?
    end

    # Returns a hash of attributes, according to the attributes existent in
    # self.class.mail_attributes.
    def attributes
      self.class.mail_attributes.inject({}) do |hash, attr|
        hash[attr.to_s] = send(attr)
        hash
      end
    end

    # Always return true so when using form_for, the default method will be post.
    def new_record?
      true
    end

    def persisted?
      false
    end

    # Always return nil so when using form_for, the default method will be post.
    def id
      nil
    end

    # Create just check validity, and if so, trigger callbacks.
    def create
      if valid?
        _run_create_callbacks { true }
      else
        false
      end
    end
    alias :save :create
  end
end
{'fraction_non_alphanumeric': 0.05934718100890208, 'fraction_numerical': 0.0013188262446422684, 'mean_word_length': 2.3014145810663766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2319388', 'n_tokens_mistral': 843, 'n_tokens_neox': 819, 'n_words': 294}