<commit_before># Sinatra
require 'sinatra/base'
require 'sinatra/contrib'
require 'json'

# Libs
require 'dalli'
require 'net/telnet'

# Project files
require_relative './extensions'

module MemcachedManager
  class API < Sinatra::Base
    enable :inline_templates
    enable :sessions
    
    set :public_folder, 'public'

    helpers Sinatra::MemcachedSettings
    helpers Sinatra::MemcachedConnection
    helpers Sinatra::MemcachedInspector
    helpers Sinatra::Errors
    helpers Sinatra::APIResponse

    before do
      content_type :json

      setup_errors

      try { setup_memcached(memcached_host(session), memcached_port(session)) }
    end

    after do
      close_memcached
    end

    # Needs refactoring
    get '/config.json' do
      api_response do
        { host: memcached_host(session), port: memcached_port(session) }
      end
    end

    # Needs refactoring
    post '/config.json' do
      session['host'] = params['host']
      session['port'] = params['port']

      api_response { { errors: errors } }
    end

    post '/keys.json' do
      try { memcached_connection.set(params[:key], params[:value]) }

      api_response do
        memcached_inspect(host: memcached_host(session), port: memcached_port(session), key: params[:key])
      end
    end

    put '/keys.json' do
      try { memcached_connection.replace(params[:key], params[:value]) }

      api_response do
        memcached_inspect(host: memcached_host(session), port: memcached_port(session), key: params[:key])
      end
    end

    get '/keys.json' do
      api_response do
        memcached_inspect(host: memcached_host(session), port: memcached_port(session))
      end
    end

    get '/keys/:key.json' do
      value = memcached_connection.get(params[:key])

      try { raise 'Key not found.' if value.nil? }

      api_response { { key: params[:key], value: value } }
    end

    delete '/keys/:key.json' do
      try { memcached_connection.delete(params[:key]) }

      api_response { { key: params[:key] } }
    end

    get '/stats.json' do
      api_response { memcached_connection.stats }
    end
  end
end
<commit_msg>No more need to refactor this.<commit_after># Sinatra
require 'sinatra/base'
require 'sinatra/contrib'
require 'json'

# Libs
require 'dalli'
require 'net/telnet'

# Project files
require_relative './extensions'

module MemcachedManager
  class API < Sinatra::Base
    enable :inline_templates
    enable :sessions
    
    set :public_folder, 'public'

    helpers Sinatra::MemcachedSettings
    helpers Sinatra::MemcachedConnection
    helpers Sinatra::MemcachedInspector
    helpers Sinatra::Errors
    helpers Sinatra::APIResponse

    before do
      content_type :json

      setup_errors

      try { setup_memcached(memcached_host(session), memcached_port(session)) }
    end

    after do
      close_memcached
    end

    get '/config.json' do
      api_response do
        { host: memcached_host(session), port: memcached_port(session) }
      end
    end

    post '/config.json' do
      session['host'] = params['host']
      session['port'] = params['port']

      api_response { { errors: errors } }
    end

    post '/keys.json' do
      try { memcached_connection.set(params[:key], params[:value]) }

      api_response do
        memcached_inspect(host: memcached_host(session), port: memcached_port(session), key: params[:key])
      end
    end

    put '/keys.json' do
      try { memcached_connection.replace(params[:key], params[:value]) }

      api_response do
        memcached_inspect(host: memcached_host(session), port: memcached_port(session), key: params[:key])
      end
    end

    get '/keys.json' do
      api_response do
        memcached_inspect(host: memcached_host(session), port: memcached_port(session))
      end
    end

    get '/keys/:key.json' do
      value = memcached_connection.get(params[:key])

      try { raise 'Key not found.' if value.nil? }

      api_response { { key: params[:key], value: value } }
    end

    delete '/keys/:key.json' do
      try { memcached_connection.delete(params[:key]) }

      api_response { { key: params[:key] } }
    end

    get '/stats.json' do
      api_response { memcached_connection.stats }
    end
  end
end

{'fraction_non_alphanumeric': 0.10624263839811543, 'fraction_numerical': 0.0, 'mean_word_length': 2.949767441860465, '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': '6902682', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1284, 'n_words': 313}