<commit_before>module ScottBarron                   #:nodoc:
  module Acts                        #:nodoc:
    module StateMachine              #:nodoc:
      class InvalidState < Exception #:nodoc:
      end
      class NoInitialState < Exception #:nodoc:
      end
      
      def self.included(base)        #:nodoc:
        base.extend ActMacro
      end
      
      module SupportingClasses
        class State
          attr_reader :name
        
          def initialize(name, opts)
            @name, @opts = name, opts
          end
        
          def entering(record)
            enteract = @opts[:enter]
            record.send(:run_transition_action, enteract) if enteract
          end
        
          def entered(record)
            afteractions = @opts[:after]
            return unless afteractions
            Array(afteractions).each do |afteract|
              record.send(:run_transition_action, afteract)
            end
          end
        
          def exited(record)
            exitact  = @opts[:exit]
            record.send(:run_transition_action, exitact) if exitact
          end
        end

        class StateTransition
          attr_reader :from, :to, :opts
          
          def initialize(opts)
            @from, @to, @guard = opts[:from], opts[:to], opts[:guard]
            @opts = opts
          end
          
          def guard(obj)
            @guard ? obj.send(:run_transition_action, @guard) : true
          end

          def perform(record)
            return false unless guard(record)
            loopback = record.current_state == to
            states = record.class.read_inheritable_attribute(:states)
            next_state = states[to]
            old_state = states[record.current_state]
          
            next_state.entering(record) unless loopback
          
            record.update_attribute(record.class.state_column, to.to_s)
          
            next_state.entered(record) unless loopback
            old_state.exited(record) unless loopback
            true
          end
          <commit_msg>use only symbols for states<commit_after>module ScottBarron                   #:nodoc:
  module Acts                        #:nodoc:
    module StateMachine              #:nodoc:
      class InvalidState < Exception #:nodoc:
      end
      class NoInitialState < Exception #:nodoc:
      end
      
      def self.included(base)        #:nodoc:
        base.extend ActMacro
      end
      
      module SupportingClasses
        class State
          attr_reader :name
        
          def initialize(name, opts)
            @name, @opts = name, opts
          end
        
          def entering(record)
            enteract = @opts[:enter]
            record.send(:run_transition_action, enteract) if enteract
          end
        
          def entered(record)
            afteractions = @opts[:after]
            return unless afteractions
            Array(afteractions).each do |afteract|
              record.send(:run_transition_action, afteract)
            end
          end
        
          def exited(record)
            exitact  = @opts[:exit]
            record.send(:run_transition_action, exitact) if exitact
          end
        end

        class StateTransition
          attr_reader :from, :to, :opts
          
          def initialize(opts)
            @from, @to, @guard = opts[:from], opts[:to], opts[:guard]
            @opts = opts
          end
          
          def guard(obj)
            @guard ? obj.send(:run_transition_action, @guard) : true
          end

          def perform(record)
            return false unless guard(record)
            loopback = record.current_state == to
            states = record.class.read_inheritable_attribute(:states)
            next_state = states[to.to_sym]
            old_state = states[record.current_state]
         
            next_state.entering(record) unless loopback
          
            record.update_attribute(record.class.state_column, to.to_s)
          
            next_state.entered(record) unless loopback
            old_state.exited(record) unless loopback
            true
          end
          
{'fraction_non_alphanumeric': 0.07245337159253945, 'fraction_numerical': 0.0, 'mean_word_length': 1.441914769410391, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3801722', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1042, 'n_words': 252}