<commit_before># frozen_string_literal: true
module TaskVault
  class Radio < ServerComponent
    after :reset, :port=, :key=

    attr_int_between 0, nil, :port, default: 2016, serialize: true, always: true
    attr_string :key, default: 'changeme', serialize: true, always: true
    attr_array_of String, :components, default: [], add_rem: true, serialize: true, always: true
    attr_reader :controller

    def start
      queue_msg('Starting up component.', severity: :info)
      super
    end

    def stop
      queue_msg('Stopping component.', severity: :info)
      @controller.stop
      super
    end

    def self.description
      'Remote control your TaskVault server! Radio provides a controller that can host the TaskVault server and its components over a TCP socket.' \
      'It utilizes the Ava library to do this and can be connected to via an Ava::Client or the TaskVault::Client.'
    end

    def running?
      @controller.running?
    end

    def method_missing(*args)
      @controller.send(*args)
    end

    def respond_to_missing?(method, include_private = false)
      @controller.respond_to?(method) || super
    end

    protected

    def setup_defaults
      @controller = Ava::Controller.new(port: @port, key: @key)
    end

    def register_objects
      { server: @parent }.merge(@parent.components).each do |component|
        @controller.register(name => component) if @components.empty? || @components.include?(component.name.to_s)
      end
    end

    def reset
      @controller.key = @key
      @controller.port = @port
      restart if running?
    end

    def run
      @controller.start
      sleep(1)
      register_objects
      sleep(1) while @controller.running?
    end
  end
end<commit_msg>Fixed bug in radio after component change in server.<commit_after># frozen_string_literal: true
module TaskVault
  class Radio < ServerComponent
    after :reset, :port=, :key=

    attr_int_between 0, nil, :port, default: 2016, serialize: true, always: true
    attr_string :key, default: 'changeme', serialize: true, always: true
    attr_array_of String, :components, default: [], add_rem: true, serialize: true, always: true
    attr_reader :controller

    def start
      queue_msg('Starting up component.', severity: :info)
      super
    end

    def stop
      queue_msg('Stopping component.', severity: :info)
      @controller.stop
      super
    end

    def self.description
      'Remote control your TaskVault server! Radio provides a controller that can host the TaskVault server and its components over a TCP socket.' \
      'It utilizes the Ava library to do this and can be connected to via an Ava::Client or the TaskVault::Client.'
    end

    def running?
      @controller.running?
    end

    def method_missing(*args)
      @controller.send(*args)
    end

    def respond_to_missing?(method, include_private = false)
      @controller.respond_to?(method) || super
    end

    protected

    def setup_defaults
      @controller = Ava::Controller.new(port: @port, key: @key)
    end

    def register_objects
      ([@parent] + @parent.components).each do |component|
        name = component.is_a?(TaskVault::Server) ? 'server' : component.name
        @controller.register(name => component) if @components.empty? || @components.include?(component.name.to_s)
      end
    end

    def reset
      @controller.key = @key
      @controller.port = @port
      restart if running?
    end

    def run
      @controller.start
      sleep(1)
      register_objects
      sleep(1) while @controller.running?
    end
  end
end
{'fraction_non_alphanumeric': 0.09166666666666666, 'fraction_numerical': 0.0038888888888888888, 'mean_word_length': 2.944140197152245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4764094', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1022, 'n_words': 336}