<commit_before>module Lotus
  module Entity
    # Dirty tracking for entities
    #
    # @since x.x.x
    module DirtyTracking
      # Override setters for attributes to support dirty tracking
      #
      # @since x.x.x
      #
      # @example Dirty tracking
      #   require 'lotus/model'
      #
      #   class User
      #     include Lotus::Entity
      #     include Lotus::Entity::DirtyTracking
      #
      #     attributes :name
      #   end
      #
      #   article = Article.new(title: 'Generation P')
      #   article.changed? # => false
      #   article.title = 'Master and Margarita'
      #   article.changed? # => true
      #   article.changed_attributes # => {:title => 'Generation P'}
      #
      def self.included(base)
        base.class_eval do
          extend ClassMethods
        end
      end

      module ClassMethods
        # Override attribute accessors function.
        # Create setter methods with attribute values checking.
        # If the new value or a changed, added to @changed_attributes.
        #
        # @params attr [Symbol] an attribute name
        #
        # @since x.x.x
        #
        # @see Lotus::Entity
        #
        # @api private
        def define_attr_accessor(attr)
          attr_reader(attr)
          define_method "#{attr}=" do |val|
            _attribute_changed(attr) if val != __send__(attr)
            instance_variable_set("@#{attr}", val)
          end<commit_msg>Change implementation create setter methods<commit_after>module Lotus
  module Entity
    # Dirty tracking for entities
    #
    # @since x.x.x
    module DirtyTracking
      # Override setters for attributes to support dirty tracking
      #
      # @since x.x.x
      #
      # @example Dirty tracking
      #   require 'lotus/model'
      #
      #   class User
      #     include Lotus::Entity
      #     include Lotus::Entity::DirtyTracking
      #
      #     attributes :name
      #   end
      #
      #   article = Article.new(title: 'Generation P')
      #   article.changed? # => false
      #   article.title = 'Master and Margarita'
      #   article.changed? # => true
      #   article.changed_attributes # => {:title => 'Generation P'}
      #
      def self.included(base)
        base.class_eval do
          extend ClassMethods
        end
      end

      module ClassMethods
        # Override attribute accessors function.
        # Create setter methods with attribute values checking.
        # If the new value or a changed, added to @changed_attributes.
        #
        # @params attr [Symbol] an attribute name
        #
        # @since x.x.x
        #
        # @see Lotus::Entity
        #
        # @api private
        def define_attr_accessor(attr)
          attr_reader(attr)
          class_eval %{
            def #{ attr }=(value)
              _attribute_changed(:#{ attr }) if value != @#{ attr }
              @#{ attr } = value
            end
          }
{'fraction_non_alphanumeric': 0.09026369168356999, 'fraction_numerical': 0.0, 'mean_word_length': 1.6826835902085222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7640063', 'n_tokens_mistral': 821, 'n_tokens_neox': 817, 'n_words': 222}