<commit_before>module NotifyOn
  module Helpers
    extend ActiveSupport::Concern

    included do

      def notify_on_string_conversion(input)
        (output = input.to_s).scan(/{[\w\_]+}/).each do |match|
          output = output.gsub(/#{match}/, send(match.gsub(/[^\w\_]/, '')).to_s)
        end
        output
      end

      def notify_on_link(input)
        return notify_on_string_conversion(input) unless input.is_a?(Array)
        args = []
        input[1..-1].each do |arg|
          args << if arg == :self
            self
          else
            arg.is_a?(String) ? arg : send(arg)
          end
        end
        Rails.application.routes.url_helpers.send(input[0], *args)
      end

      def notify_on_send_email(notification, template)
        NotifyOn.configuration.mailer_class.constantize
                .notify(notification.id, template).deliver_now
      end

      def notify_on_trigger_pusher(channel, event, attrs)
        Pusher.app_id = NotifyOn.configuration.pusher_app_id
        Pusher.key    = NotifyOn.configuration.pusher_key
        Pusher.secret = NotifyOn.configuration.pusher_secret

        channel = notify_on_string_conversion(channel)
        event = notify_on_string_conversion(event)

        msg  = "Pusher Event: #{event} // To Channel: #{channel}\n#{attrs}"
        Rails.logger.debug(msg)

        Pusher.trigger_async(channel, event, attrs)
      end

    end<commit_msg>add support for "{:env}" and "{:recipient_id}" in Pusher channel and event arguments<commit_after>module NotifyOn
  module Helpers
    extend ActiveSupport::Concern

    included do

      def notify_on_string_conversion(input)
        (output = input.to_s).scan(/{[\w\_]+}/).each do |match|
          output = output.gsub(/#{match}/, send(match.gsub(/[^\w\_]/, '')).to_s)
        end
        output
      end

      def notify_on_link(input)
        return notify_on_string_conversion(input) unless input.is_a?(Array)
        args = []
        input[1..-1].each do |arg|
          args << if arg == :self
            self
          else
            arg.is_a?(String) ? arg : send(arg)
          end
        end
        Rails.application.routes.url_helpers.send(input[0], *args)
      end

      def notify_on_send_email(notification, template)
        NotifyOn.configuration.mailer_class.constantize
                .notify(notification.id, template).deliver_now
      end

      def notify_on_trigger_pusher(channel, event, attrs)
        Pusher.app_id = NotifyOn.configuration.pusher_app_id
        Pusher.key    = NotifyOn.configuration.pusher_key
        Pusher.secret = NotifyOn.configuration.pusher_secret

        recipient_id = JSON.parse(attrs[:notification])["recipient_id"].to_s

        channel = notify_on_string_conversion(channel)
          .gsub(/\{:env}/, Rails.env.downcase)
          .gsub(/\{:recipient_id}/, recipient_id)
        event = notify_on_string_conversion(event)
          .gsub(/\{:env}/, Rails.env.downcase)
          .gsub(/\{:recipient_id}/, recipient_id)

        msg  = "Pusher Event: #{event} // To Channel: #{channel}\n#{attrs}"
        Rails.logger.debug(msg)

        Pusher.trigger_async(channel, event, attrs)
      end

    end
{'fraction_non_alphanumeric': 0.11683848797250859, 'fraction_numerical': 0.0018744142455482662, 'mean_word_length': 2.3493723849372383, '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': '4406213', 'n_tokens_mistral': 1016, 'n_tokens_neox': 1012, 'n_words': 178}