<commit_before>require 'bigdecimal'
module CouchPotato
  module Persistence
    module DirtyAttributes

      def self.included(base) #:nodoc:
        base.send :include, ActiveModel::Dirty
        base.class_eval do
          extend ClassMethods
          after_save :reset_dirty_attributes
        end
      end

      def initialize(attributes = {})
        super
      end

      # returns true if a model has dirty attributes, i.e. their value has changed since the last save
      def dirty?
        changed? || @forced_dirty
      end

      # marks a model as dirty
      def is_dirty
        @forced_dirty = true
      end

      private

      def reset_dirty_attributes
        @previously_changed = changes
        @changed_attributes.clear
        @forced_dirty = nil
      end

      def clone_attribute(value)
        if [Fixnum, Symbol, TrueClass, FalseClass, NilClass, Float, BigDecimal].include?(value.class)
          value
        elsif [Hash, Array].include?(value.class)
          #Deep clone
          Marshal::load(Marshal::dump(value))
        else
          value.clone
        end
      end

      module ClassMethods
        def property(name, *args)
          define_attribute_methods [name]
          super name, *args
        end
      end
    end
  end
end<commit_msg>activemodel 3.0 required that we cann define_attribute_methods with all the property names<commit_after>require 'bigdecimal'
module CouchPotato
  module Persistence
    module DirtyAttributes

      def self.included(base) #:nodoc:
        base.send :include, ActiveModel::Dirty
        base.class_eval do
          extend ClassMethods
          after_save :reset_dirty_attributes
        end
      end

      def initialize(attributes = {})
        super
      end

      # returns true if a model has dirty attributes, i.e. their value has changed since the last save
      def dirty?
        changed? || @forced_dirty
      end

      # marks a model as dirty
      def is_dirty
        @forced_dirty = true
      end

      private

      def reset_dirty_attributes
        @previously_changed = changes
        @changed_attributes.clear
        @forced_dirty = nil
      end

      def clone_attribute(value)
        if [Fixnum, Symbol, TrueClass, FalseClass, NilClass, Float, BigDecimal].include?(value.class)
          value
        elsif [Hash, Array].include?(value.class)
          #Deep clone
          Marshal::load(Marshal::dump(value))
        else
          value.clone
        end
      end

      module ClassMethods
        def property(name, *args)
          undefine_attribute_methods
          define_attribute_methods property_names + [name]
          super name, *args
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06078359575247162, 'fraction_numerical': 0.0007323324789454412, 'mean_word_length': 1.9956140350877194, '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': '7480007', 'n_tokens_mistral': 736, 'n_tokens_neox': 716, 'n_words': 218}