class Kiyohime::Parsers::ChannelParser
Microservices receive and send messages along channels, channel names can be derived from the name of the type
Public Instance Methods
parse_type_and_method_to_channel_name(type_name, method_name)
click to toggle source
Convert a type name and method name to a channel name. A type name can be a Ruby type or a string representation of the type name. A method name can be a symbol or a string
# File lib/kiyohime/parsers/channel_parser.rb, line 21 def parse_type_and_method_to_channel_name(type_name, method_name) type_name = type_name.to_s.downcase.gsub(/::/, '.') method_name = method_name.to_s.downcase if type_name.empty? || method_name.empty? || !type_name_valid?(type_name) || !method_name_valid?(method_name) raise Kiyohime::Exceptions::UnsupportedChannelName else "#{type_name}.#{method_name}" end end
parse_type_to_channel_name(type_name)
click to toggle source
Convert a type name to a channel name. A type name can be a Ruby type or a string representation of the type name
# File lib/kiyohime/parsers/channel_parser.rb, line 10 def parse_type_to_channel_name(type_name) type_name = type_name.to_s.downcase.gsub(/::/, '.') if type_name.empty? || !type_name_valid?(type_name) raise Kiyohime::Exceptions::UnsupportedChannelName else type_name end end
Private Instance Methods
method_name_valid?(method_name)
click to toggle source
Validate the method name to make sure we can convert it to a valid channel name
# File lib/kiyohime/parsers/channel_parser.rb, line 40 def method_name_valid?(method_name) (/^[a-z]+[_0-9a-zA-Z]*$/ =~ method_name).nil? ? false : true end
type_name_valid?(channel_name)
click to toggle source
Validate the type name to make sure we can convert it to a valid channel name
# File lib/kiyohime/parsers/channel_parser.rb, line 35 def type_name_valid?(channel_name) (/^[a-z]+(\.[a-z]+)*(\.[a-z]+){0,1}$/ =~ channel_name).nil? ? false : true end