Sha256: 7450203b730d3aa0c90f5f628f50e133aa28536f6b6d062c62be3eb67c398f79

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Polyn
  class Cli
    class Naming
      ##
      # Convert a dot separated name into a colon separated name
      def self.dot_to_colon(str)
        str.gsub(".", ":")
      end

      def self.validate_stream_name!(name)
        unless name.match(/^[a-zA-Z0-9_]+$/)
          raise Polyn::Cli::Error,
            "Stream name must be all alphanumeric, uppercase, and underscore separated. Got #{name}"
        end
      end

      def self.format_stream_name(name)
        name.upcase
      end

      def self.validate_destination_name!(name)
        unless name.is_a?(String) && name.match?(/\A[a-z0-9]+(?:(?:\.|:)[a-z0-9]+)*\z/)
          raise Polyn::Cli::Error,
            "Event destination must be lowercase, alphanumeric and dot/colon separated, got #{name}"
        end
      end

      def self.validate_event_type!(name)
        unless name.is_a?(String) && name.match?(/\A[a-z0-9]+(?:\.[a-z0-9]+)*\z/)
          raise Polyn::Cli::Error,
            "Event types must be lowercase, alphanumeric and dot separated"
        end
      end

      def self.dot_to_underscore(name)
        name.gsub(".", "_")
      end

      def self.colon_to_underscore(name)
        name.gsub(":", "_")
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
polyn-cli-0.1.9 lib/polyn/cli/naming.rb
polyn-cli-0.1.8 lib/polyn/cli/naming.rb
polyn-cli-0.1.7 lib/polyn/cli/naming.rb
polyn-cli-0.1.6 lib/polyn/cli/naming.rb
polyn-cli-0.1.5 lib/polyn/cli/naming.rb
polyn-cli-0.1.4 lib/polyn/cli/naming.rb
polyn-cli-0.1.3 lib/polyn/cli/naming.rb
polyn-cli-0.1.2 lib/polyn/cli/naming.rb
polyn-cli-0.1.1 lib/polyn/cli/naming.rb
polyn-cli-0.1.0 lib/polyn/cli/naming.rb