<commit_before>require 'specter/device'

module Specter
  module Middleware
    class Service < Base

      METHODS = %w(
        devs
      ).freeze

      def call(env)
        #raise NoMethodError unless METHODS.include?(request.command)
        if METHODS.include?(env.command)
          method_name = env.command.to_sym

          result = send(method_name, *env.params)
          result['STATUS'] ||= [
            {
              'STATUS' => 'S',
              'When' => Time.now.to_i,
              'Code' => 1, # simulate real codes? nah...
              'Msg' => 'Simulated response',
              'Description' => "specter #{Specter::VERSION}"
            }
          ]

          env.merge!(result)
        else
          @app.call(env)
        end
      end

      protected

      def devs
        {
          'DEVS' => Celluloid::Actor[:devices].collect(&:to_hash)
        }
      end
    end # Service
  end # Middleware
end # Specter<commit_msg>Add dynamic summary<commit_after>require 'specter/device'

module Specter
  module Middleware
    class Service < Base

      METHODS = %w(
        devs summary
      ).freeze

      def call(env)
        #raise NoMethodError unless METHODS.include?(request.command)
        if METHODS.include?(env.command)
          method_name = env.command.to_sym

          result = send(method_name, *env.params)
          result['STATUS'] ||= [
            {
              'STATUS' => 'S',
              'When' => Time.now.to_i,
              'Code' => 1, # simulate real codes? nah...
              'Msg' => 'Simulated response',
              'Description' => "specter #{Specter::VERSION}"
            }
          ]

          env.merge!(result)
        else
          @app.call(env)
        end
      end

      protected

      def devs
        {
          'DEVS' => Celluloid::Actor[:devices].collect(&:to_hash)
        }
      end

      def summary
        {
          'SUMMARY' => [Celluloid::Actor[:devices].collect(&:to_hash).inject(&:merge)]
        }
      end
    end # Service
  end # Middleware
end # Specter
{'fraction_non_alphanumeric': 0.12090558766859345, 'fraction_numerical': 0.0009633911368015414, 'mean_word_length': 1.5673671199011125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '226261', 'n_tokens_mistral': 628, 'n_tokens_neox': 596, 'n_words': 127}