<commit_before>module WebConsole
  class REPLSession
    include Mutex_m

    include ActiveModel::Model
    include ActiveModel::Serializers::JSON

    INMEMORY_STORAGE = {}

    ATTRIBUTES = [ :id, :input, :output, :prompt, :binding ].each do |attr|
      attr_accessor attr
    end

    class NotFound < StandardError
      def to_json(*)
        {error: message}.to_json
      end
    end

    class << self
      # Finds a session by its id.
      def find(id)
        INMEMORY_STORAGE[id.to_i] or raise NotFound.new('Session unavailable')
      end

      # Creates an already persisted consolse session.
      #
      # Use this method if you need to persist a session, without providing it
      # any input.
      def create(binding)
        INMEMORY_STORAGE[(model = new({ binding: binding })).id] = model
      end
    end

    def initialize(attributes = {})
      attributes[:binding] = attributes[:binding] || TOPLEVEL_BINDING
      @repl = WebConsole::REPL.default.new attributes[:binding]

      super(attributes)
      ensure_consequential_id!
      populate_repl_attributes!(initial: true)
    end

    # Saves the model into the in-memory storage.<commit_msg>Minor styling fix<commit_after>module WebConsole
  class REPLSession
    include Mutex_m

    include ActiveModel::Model
    include ActiveModel::Serializers::JSON

    INMEMORY_STORAGE = {}

    ATTRIBUTES = [ :id, :input, :output, :prompt, :binding ].each do |attr|
      attr_accessor attr
    end

    class NotFound < StandardError
      def to_json(*)
        { error: message }.to_json
      end
    end

    class << self
      # Finds a session by its id.
      def find(id)
        INMEMORY_STORAGE[id.to_i] or raise NotFound.new('Session unavailable')
      end

      # Creates an already persisted consolse session.
      #
      # Use this method if you need to persist a session, without providing it
      # any input.
      def create(binding)
        INMEMORY_STORAGE[(model = new({ binding: binding })).id] = model
      end
    end

    def initialize(attributes = {})
      attributes[:binding] ||= TOPLEVEL_BINDING
      @repl = WebConsole::REPL.default.new attributes[:binding]

      super(attributes)
      ensure_consequential_id!
      populate_repl_attributes!(initial: true)
    end

    # Saves the model into the in-memory storage.
{'fraction_non_alphanumeric': 0.08675213675213675, 'fraction_numerical': 0.0, 'mean_word_length': 2.6635367762128324, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3853947', 'n_tokens_mistral': 711, 'n_tokens_neox': 681, 'n_words': 199}