<commit_before>require 'comma'

module Beso
  class Job
    def initialize( name, options )
      @name  = name
      @table = options.delete :table
      @props = { }
    end

    def prop( name, title=nil )
      @props[ name.to_s ] = ( title || name.to_s.titleize )
    end

    def event_title
      @name.to_s.titleize
    end

    def model_class
      @table.to_s.classify.constantize
    end

    def to_csv
      model_class.class_eval <<-EOS
        def event_title
          "#{event_title}"
        end
      EOS

      model_class.instance_eval <<-EOS
        comma do
          id          'Identity'
          created_at  'Timestamp' do |t|
            t.to_i
          end
          event_title 'Event'
          #{custom_props}
        end
      EOS

      model_class.all.to_comma
    end

    protected

    def custom_props
      @props.reduce( '' ) do |memo, (name, title)|
        memo << "#{name} 'Prop:#{title}'\n"
      end
    end
  end
end
<commit_msg>Avoid using string instance eval for model class<commit_after>require 'comma'

module Beso
  class Job
    def initialize( name, options )
      @name  = name
      @table = options.delete :table
      @props = { }
    end

    def prop( name, title=nil )
      @props[ name.to_sym ] = ( title || name.to_s.titleize )
    end

    def event_title
      @name.to_s.titleize
    end

    def model_class
      @table.to_s.classify.constantize
    end

    def to_csv
      model_class.class_eval <<-EOS
        def event_title
          "#{event_title}"
        end
      EOS

      model_class.instance_exec( @props ) do |args|
        comma do
          id          'Identity'
          created_at  'Timestamp' do |m|
            m.to_i
          end
          event_title 'Event'

          args.each do |name, title|
            self.send name, "Prop:#{title}"
          end
        end
      end

      model_class.all.to_comma
    end
  end
end

{'fraction_non_alphanumeric': 0.08869294605809129, 'fraction_numerical': 0.0, 'mean_word_length': 1.5997304582210243, 'pattern_counts': {'":': 0, '<': 11, '<?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': '755425', 'n_tokens_mistral': 638, 'n_tokens_neox': 626, 'n_words': 157}