<commit_before>require 'active_record'
require 'active_support/all'
require 'split_date_time/version'

module SplitDateTime
  extend ActiveSupport::Concern

  included do
    extend ClassMethods
    before_save :concatenate_datetime
  end

  module ClassMethods


    def split_date_time(options = {})
      options[:prefix] ||= options[:field]
      define_split_accessors(options[:field], options[:prefix])
      define_concatenation_callback(options[:field], options[:prefix])
    end

    def define_split_accessors(field, prefix)
      define_method :"#{prefix}_time" do 
        field_val = send(field)
        field_val.strftime('%H:%M') if field_val.present?
      end
      define_method :"#{prefix}_time=" do |val|
        instance_variable_set :"@#{prefix}_time", val
      end
      define_method :"#{prefix}_date" do 
        field_val = send(field)
        field_val.strftime('%m/%d/%Y') if field_val.present?
      end
      define_method :"#{prefix}_date=" do |val|
        instance_variable_set :"@#{prefix}_date", val
      end
    end

    def define_concatenation_callback(field, prefix)
      define_method :concatenate_datetime do 
        Time do 
          date_val = instance_variable_get :"@#{prefix}_date"
          time_val = instance_variable_get :"@#{prefix}_time"
          self.send "#{field}=", Time.parse("#{date_val} #{time_val}")
        end   
      end
    end
  end
end

ActiveRecord::Base.send :include, SplitDateTime<commit_msg>correctly implement concatenation callback.<commit_after>require 'active_record'
require 'active_support/all'
require 'split_date_time/version'

module SplitDateTime
  extend ActiveSupport::Concern

  included do
    extend ClassMethods
  end

  module ClassMethods
    def split_date_time(options = {})
      options[:prefix] ||= options[:field]
      define_split_accessors(options[:field], options[:prefix])
      define_concatenation_callback(options[:field], options[:prefix])
    end

    def define_split_accessors(field, prefix)
      define_method :"#{prefix}_time" do
        field_val = send(field)
        field_val.strftime('%H:%M') if field_val.present?
      end
      define_method :"#{prefix}_time=" do |val|
        instance_variable_set :"@#{prefix}_time", val
      end
      define_method :"#{prefix}_date" do
        field_val = send(field)
        field_val.strftime('%m/%d/%Y') if field_val.present?
      end
      define_method :"#{prefix}_date=" do |val|
        instance_variable_set :"@#{prefix}_date", val
      end
    end

    def define_concatenation_callback(field, prefix)
      before_save :"concatenate_#{field}"
      define_method :"concatenate_#{field}" do
        Time do
          date_val = instance_variable_get :"@#{prefix}_date"
          time_val = instance_variable_get :"@#{prefix}_time"
          self.send "#{field}=", Time.parse("#{date_val} #{time_val}")
        end
      end
    end
  end
end

ActiveRecord::Base.send :include, SplitDateTime
{'fraction_non_alphanumeric': 0.1163575042158516, 'fraction_numerical': 0.0, 'mean_word_length': 3.400593471810089, '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': '5358412', 'n_tokens_mistral': 918, 'n_tokens_neox': 916, 'n_words': 186}