<commit_before>module GtkApp
module SignalSupport

  def self.included(base)
    base.extend(ClassMethods)
    base.send(:include, InstanceMethods)
  end

  module ClassMethods
    attr_reader :signal_connections

    def on(widget_name, signal_name, receiver_method=nil, &block)

      sc = SignalConnection.new do
        @widget_name = widget_name
        @signal_name = signal_name
        @receiver_method = receiver_method
        @receiver_block = block if block_given?
      end

      @signal_connections ||= []
      @signal_connections << sc
    end

  end
  
  module InstanceMethods

    def establish_signal_connections
      return unless self.class.signal_connections

      self.class.signal_connections.each do |signal_connection|
        signal_connection.with do |conn|
          widget = @view.send conn.widget_name
          if conn.receiver_block
            widget.signal_connect conn.signal_name do |*args|
              self.instance_exec(*args, &conn.receiver_block)
            end
          else
            widget.signal_connect conn.signal_name do |*args|
              self.send conn.receiver_method_name, *args
            end
          end
        end
      end
    end

  end

  class SignalConnection
    attr_accessor :widget_name, :signal_name
    attr_accessor :receiver_method, :receiver_block

    def initialize(&block)
      instance_eval(&block)
    end

    def with
      yield(self)
    end

  end

end
end<commit_msg>Added YARD doc.<commit_after>module GtkApp
module SignalSupport

  def self.included(base)
    base.extend(ClassMethods)
    base.send(:include, InstanceMethods)
  end

  module ClassMethods
    attr_reader :signal_connections

    # @param [Symbol] widget_name
    # @param [String] signal_name
    # @param [Symbol] receiver_method
    # @yield [...]
    def on(widget_name, signal_name, receiver_method=nil, &block)

      sc = SignalConnection.new do
        @widget_name = widget_name
        @signal_name = signal_name
        @receiver_method = receiver_method
        @receiver_block = block if block_given?
      end

      @signal_connections ||= []
      @signal_connections << sc
    end

  end
  
  module InstanceMethods

    def establish_signal_connections
      return unless self.class.signal_connections

      self.class.signal_connections.each do |signal_connection|
        signal_connection.with do |conn|
          widget = @view.send conn.widget_name
          if conn.receiver_block
            widget.signal_connect conn.signal_name do |*args|
              self.instance_exec(*args, &conn.receiver_block)
            end
          else
            widget.signal_connect conn.signal_name do |*args|
              self.send conn.receiver_method_name, *args
            end
          end
        end
      end
    end

  end

  class SignalConnection
    attr_accessor :widget_name, :signal_name
    attr_accessor :receiver_method, :receiver_block

    def initialize(&block)
      instance_eval(&block)
    end

    def with
      yield(self)
    end

  end

end
end
{'fraction_non_alphanumeric': 0.06673209028459273, 'fraction_numerical': 0.0, 'mean_word_length': 2.4205816554809845, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3601523', 'n_tokens_mistral': 908, 'n_tokens_neox': 862, 'n_words': 203}