<commit_before>require "maktoub/engine"

module Maktoub
  class << self
    attr_accessor :from,
                  :twitter_url,
                  :facebook_url,
                  :google_plus_url,
                  :linkedin_url,
                  :subscription_preferences_url,
                  :logo,
                  :home_domain,
                  :app_name, 
                  :unsubscribe_method

    attr_writer :email_field, :name_field

    def email_field
      @email_field || :email
    end

    def name_field
      @name_field || :name
    end

    def subscribers
      @subscribers.call
    end

    def subscribers_extractor (&block)
      @subscribers = Proc.new &block
    end
    
    def unsubscribe(email)
      if subscribers.class.respond_to?(:to_sql) #check if ActiveRecord relation
        subscribers.where(email_field => email).first.send(unsubscribe_method)
      else
        subscribers.select do |s| <commit_msg>correctly identify activerecord object type<commit_after>require "maktoub/engine"

module Maktoub
  class << self
    attr_accessor :from,
                  :twitter_url,
                  :facebook_url,
                  :google_plus_url,
                  :linkedin_url,
                  :subscription_preferences_url,
                  :logo,
                  :home_domain,
                  :app_name, 
                  :unsubscribe_method

    attr_writer :email_field, :name_field

    def email_field
      @email_field || :email
    end

    def name_field
      @name_field || :name
    end

    def subscribers
      @subscribers.call
    end

    def subscribers_extractor (&block)
      @subscribers = Proc.new &block
    end
    
    def unsubscribe(email)
      if Maktoub.subscribers.class.parents.include?(ActiveRecord) #check if ActiveRecord relation
        subscribers.where(email_field => email).first.send(unsubscribe_method)
      else
        puts 'WARNING!!! Use ActiveRecord query methods to find subscribers. Falling back to iterating through subscribers array (slow!).'
        subscribers.select do |s| 
{'fraction_non_alphanumeric': 0.07063911580970687, 'fraction_numerical': 0.0, 'mean_word_length': 1.9078212290502794, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '601747', 'n_tokens_mistral': 619, 'n_tokens_neox': 572, 'n_words': 131}