class SmtpMock::CommandLineArgsBuilder

Constants

IP_ADDRESS_PATTERN
PERMITTED_ATTRS

Public Class Methods

call(**options) click to toggle source
# File lib/smtp_mock/command_line_args_builder.rb, line 49
def call(**options)
  new(options).to_command_line_args_string
rescue Dry::Struct::Error => error
  raise SmtpMock::Error::Argument, error.message
end

Private Class Methods

define_attribute() click to toggle source
# File lib/smtp_mock/command_line_args_builder.rb, line 57
def define_attribute
  ->((type, attributes)) { attributes.each { |field| attribute?(field, type) } }
end

Public Instance Methods

to_command_line_args_string() click to toggle source
# File lib/smtp_mock/command_line_args_builder.rb, line 67
def to_command_line_args_string
  to_h.map do |key, value|
    key = to_camel_case(key)
    value = format_by_type(value)
    value ? "-#{key}=#{value}" : "-#{key}"
  end.sort.join(' ')
end

Private Instance Methods

format_by_type(object) click to toggle source
# File lib/smtp_mock/command_line_args_builder.rb, line 85
def format_by_type(object)
  case object
  when ::Array then to_quoted(object.join(','))
  when ::String then to_quoted(object)
  when ::TrueClass then nil
  else object
  end
end
to_camel_case(symbol) click to toggle source
# File lib/smtp_mock/command_line_args_builder.rb, line 77
def to_camel_case(symbol)
  symbol.to_s.gsub(/_(\D)/) { ::Regexp.last_match(1).upcase }
end
to_quoted(string) click to toggle source
# File lib/smtp_mock/command_line_args_builder.rb, line 81
def to_quoted(string)
  "\"#{string}\""
end