<commit_before>module FayeRails
  class Controller
    class Channel

      attr_reader :channel, :endpoint

      def initialize(channel, endpoint=nil)
        @channel = channel
        @endpoint = endpoint
      end

      def client
        FayeRails.client(endpoint)
      end

      def publish(message)
        client.publish(channel, message)
      end

      def monitor(event, &block)
        raise ArgumentError, "Unknown event #{event.inspect}" unless [:subscribe,:unsubscribe,:publish].member? event

        FayeRails.server(endpoint).bind(event) do |*args|
          Monitor.new.tap do |m|
            m.client_id = args.shift
            m.channel = args.shift
            m.data = args.shift
            m.instance_eval(&block) if m.channel.match(/^#{channel.gsub('*', "[^\/]*").gsub('**', '.*')}$/)
          end
        end
      end

      def filter(direction=:any, &block)
        filter = FayeRails::Filter.new(channel, direction, block)
        server = FayeRails.server(endpoint)
        server.add_extension(filter)
        filter.server = server
        filter
      end

      def subscribe(&block)<commit_msg>Refractor channel pattern matcher using File.fnmatch. #18<commit_after>module FayeRails
  class Controller
    class Channel

      attr_reader :channel, :endpoint

      def initialize(channel, endpoint=nil)
        @channel = channel
        @endpoint = endpoint
      end

      def client
        FayeRails.client(endpoint)
      end

      def publish(message)
        client.publish(channel, message)
      end

      def monitor(event, &block)
        raise ArgumentError, "Unknown event #{event.inspect}" unless [:subscribe,:unsubscribe,:publish].member? event

        FayeRails.server(endpoint).bind(event) do |*args|
          Monitor.new.tap do |m|
            m.client_id = args.shift
            m.channel = args.shift
            m.data = args.shift
            m.instance_eval(&block) if File.fnmatch(channel, m.channel)
          end
        end
      end

      def filter(direction=:any, &block)
        filter = FayeRails::Filter.new(channel, direction, block)
        server = FayeRails.server(endpoint)
        server.add_extension(filter)
        filter.server = server
        filter
      end

      def subscribe(&block)
{'fraction_non_alphanumeric': 0.10332749562171628, 'fraction_numerical': 0.0008756567425569177, 'mean_word_length': 2.186889818688982, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7642410', 'n_tokens_mistral': 657, 'n_tokens_neox': 634, 'n_words': 149}