<commit_before>require 'active_model'

class Presenter
  extend ActiveModel::Naming
  include ActiveModel::Conversion
  include ActiveModel::Validations

  validate :instance_validations

  # Constructs a new Presenter object which can be passed to a form or
  # generally filled with values. It must take a model name, which is a string
  # that is the name of the model you are presenting. It can also take a
  # validator and fields.
  #
  #   Presenter.new('sign_up',
  #                 :fields => [:account_name, :email, :password],
  #                 :validator => SignUpValidator)
  def initialize(model_name, opts = {})
    @@model_name = model_name

    @validator = opts[:validator]
    @fields   = opts[:fields]

    self.class.send(:attr_accessor,*@fields) unless @fields.nil? || @fields.empty?
  end

  def instance_validations
    validates_with(@validator, :attributes => @fields) if @validator
  end

  def self.model_name # :nodoc:
    ActiveModel::Name.new(Class.new do
      attr_reader :name
      def initialize(n)
        @name = n
      end
    end.new(@@model_name))
  end

  def persisted? # :nodoc:
    false
  end

  # Set the params from the form using this.
  #
  #   @sign_up_presenter.with_params(params[:sign_up])
  def with_params(params = {})
    params.each {|k,v| self.send("#{k}=", v)}
    self
  end<commit_msg>Shorten the ActiveModel::Naming.model_name method using Struct.<commit_after>require 'active_model'

class Presenter
  extend ActiveModel::Naming
  include ActiveModel::Conversion
  include ActiveModel::Validations

  validate :instance_validations

  # Constructs a new Presenter object which can be passed to a form or
  # generally filled with values. It must take a model name, which is a string
  # that is the name of the model you are presenting. It can also take a
  # validator and fields.
  #
  #   Presenter.new('sign_up',
  #                 :fields => [:account_name, :email, :password],
  #                 :validator => SignUpValidator)
  def initialize(model_name, opts = {})
    @@model_name = model_name

    @validator = opts[:validator]
    @fields   = opts[:fields]

    self.class.send(:attr_accessor,*@fields) unless @fields.nil? || @fields.empty?
  end

  def instance_validations
    validates_with(@validator, :attributes => @fields) if @validator
  end

  def self.model_name # :nodoc:
    model_namer = Struct.new("ModelNamer", :name).new(@@model_name)
    ActiveModel::Name.new(model_namer)
  end

  def persisted? # :nodoc:
    false
  end

  # Set the params from the form using this.
  #
  #   @sign_up_presenter.with_params(params[:sign_up])
  def with_params(params = {})
    params.each {|k,v| self.send("#{k}=", v)}
    self
  end
{'fraction_non_alphanumeric': 0.10820758189179241, 'fraction_numerical': 0.0, 'mean_word_length': 3.34185303514377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7453028', 'n_tokens_mistral': 855, 'n_tokens_neox': 850, 'n_words': 242}