<commit_before>require 'active_support/concern'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/kernel/singleton_class'
require 'active_support/core_ext/object/try'

module SimpleStates
  class TransitionException < RuntimeError; end

  autoload :Event,  'simple_states/event'
  autoload :States, 'simple_states/states'

  extend ActiveSupport::Concern

  included do
    class_attribute :state_names, :initial_state, :events
    after_initialize :init_state if respond_to?(:after_initialize)
    self.initial_state = :created
    self.events = []
  end

  module ClassMethods
    def new(*)
      super.tap { |object| States.init(object) }
    end

    def allocate
      super.tap { |object| States.init(object) }
    end

    def states(*args)
      if args.empty?
        self.state_names ||= add_states(self.initial_state)
      else
        options = args.last.is_a?(Hash) ? args.pop : {}
        self.initial_state = options[:initial].to_sym if options.key?(:initial)
        add_states(*[self.initial_state].concat(args))
      end
    end

    def add_states(*states)
      self.state_names = (self.state_names || []).concat(states.compact.map(&:to_sym)).uniq
    end

    def event(name, options = {})
      add_states(*options[:from], options[:to])
      self.events += [Event.new(name, options)]
    end
  end

  attr_reader :past_states

  def init_state
    self.state = self.class.initial_state if state.nil?
  end

  def past_states
    @past_states ||= []
  end

  def state?(state, include_past = false)
    include_past ? was_state?(state) : self.state.try(:to_sym) == state.to_sym
  end

  def was_state?(state)
    past_states.concat([self.state.try(:to_sym)]).compact.include?(state.to_sym)
  end

  def respond_to?(method, include_private = false)
    method.to_s =~ /(was_|^)(#{self.class.states.join('|')})\?$/ && self.class.state_names.include?($2.to_sym) || super
  end

  def method_missing(method, *args, &block)
    method.to_s =~ /(was_|^)(#{self.class.states.join('|')})\?$/ ? send(:"#{$1}state?", $2, *args) : super
  end
end

<commit_msg>fix 1.8.7 bug with :from array<commit_after>require 'active_support/concern'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/kernel/singleton_class'
require 'active_support/core_ext/object/try'

module SimpleStates
  class TransitionException < RuntimeError; end

  autoload :Event,  'simple_states/event'
  autoload :States, 'simple_states/states'

  extend ActiveSupport::Concern

  included do
    class_attribute :state_names, :initial_state, :events
    after_initialize :init_state if respond_to?(:after_initialize)
    self.initial_state = :created
    self.events = []
  end

  module ClassMethods
    def new(*)
      super.tap { |object| States.init(object) }
    end

    def allocate
      super.tap { |object| States.init(object) }
    end

    def states(*args)
      if args.empty?
        self.state_names ||= add_states(self.initial_state)
      else
        options = args.last.is_a?(Hash) ? args.pop : {}
        self.initial_state = options[:initial].to_sym if options.key?(:initial)
        add_states(*[self.initial_state].concat(args))
      end
    end

    def add_states(*states)
      self.state_names = (self.state_names || []).concat(states.compact.map(&:to_sym)).uniq
    end

    def event(name, options = {})
      add_states(options[:to], *options[:from])
      self.events += [Event.new(name, options)]
    end
  end

  attr_reader :past_states

  def init_state
    self.state = self.class.initial_state if state.nil?
  end

  def past_states
    @past_states ||= []
  end

  def state?(state, include_past = false)
    include_past ? was_state?(state) : self.state.try(:to_sym) == state.to_sym
  end

  def was_state?(state)
    past_states.concat([self.state.try(:to_sym)]).compact.include?(state.to_sym)
  end

  def respond_to?(method, include_private = false)
    method.to_s =~ /(was_|^)(#{self.class.states.join('|')})\?$/ && self.class.state_names.include?($2.to_sym) || super
  end

  def method_missing(method, *args, &block)
    method.to_s =~ /(was_|^)(#{self.class.states.join('|')})\?$/ ? send(:"#{$1}state?", $2, *args) : super
  end
end


{'fraction_non_alphanumeric': 0.14251949893642166, 'fraction_numerical': 0.002127156700543607, 'mean_word_length': 3.6505494505494505, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5070011', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1428, 'n_words': 265}