<commit_before>require 'rubygems'
require 'active_record'

module RedLine
	def acts_as_braintree_customer(attribute_rewriting = {})
		send :include, RedLine::Customer
		send 'braintree_customer=', attribute_rewriting
	end
	module Customer
		def self.included(base)
			base.class_eval do
				send :extend, ActiveSupport::Memoizable
				send :include, InstanceMethods
				memoize :customer
				before_create  :create_customer
				before_update  :update_customer
				before_destroy :delete_customer
				cattr_accessor :braintree_customer
			end
		end
		module InstanceMethods
			def braintree_customer_attributes
				wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id}
				attributes.symbolize_keys.inject({}) do |rewritten_hash, (original_key, value)|
					rewritten_hash[self.class.braintree_customer.fetch(original_key, original_key)] = value
					rewritten_hash
				end.reject{|key, value| !wanted_attributes.include?(key)}
			end
			def customer
				Braintree::Customer.find(customer_id)
			end
			def create_customer
				self.customer_id = Braintree::Customer.create!(braintree_customer_attributes).id
			end
			def update_customer
				Braintree::Customer.update!(customer_id, braintree_customer_attributes) && flush_cache(:customer)
			end
			def delete_customer
				Braintree::Customer.delete(customer_id)
			end
		end
	end
end

ActiveRecord::Base.extend RedLine<commit_msg>Only access a customer if there is a customer_id<commit_after>require 'rubygems'
require 'active_record'

module RedLine
	def acts_as_braintree_customer(attribute_rewriting = {})
		send :include, RedLine::Customer
		send 'braintree_customer=', attribute_rewriting
	end
	module Customer
		def self.included(base)
			base.class_eval do
				send :extend, ActiveSupport::Memoizable
				send :include, InstanceMethods
				memoize :customer
				before_create  :create_customer
				before_update  :update_customer
				before_destroy :delete_customer
				cattr_accessor :braintree_customer
			end
		end
		module InstanceMethods
			def braintree_customer_attributes
				wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id}
				attributes.symbolize_keys.inject({}) do |rewritten_hash, (original_key, value)|
					rewritten_hash[self.class.braintree_customer.fetch(original_key, original_key)] = value
					rewritten_hash
				end.reject{|key, value| !wanted_attributes.include?(key)}
			end
			def customer
				Braintree::Customer.find(customer_id) if customer_id
			end
			def create_customer
				self.customer_id = Braintree::Customer.create!(braintree_customer_attributes).id
			end
			def update_customer
				Braintree::Customer.update!(customer_id, braintree_customer_attributes) && flush_cache(:customer) if customer_id
			end
			def delete_customer
				Braintree::Customer.delete(customer_id) if customer_id
			end
		end
	end
end

ActiveRecord::Base.extend RedLine
{'fraction_non_alphanumeric': 0.08157715839564922, 'fraction_numerical': 0.0, 'mean_word_length': 5.093167701863354, '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': '4175506', 'n_tokens_mistral': 1081, 'n_tokens_neox': 910, 'n_words': 185}