module T::Mailer::Helper

Public Instance Methods

check_api_defined(klass) click to toggle source

Check gem is installed or not. If not it will raise error.

@param [String] klass the API's class name

# File lib/t/mailer/helper.rb, line 7
def check_api_defined(klass)
  unless T::Mailer.const_defined?(klass)
    fail Error::DeliverySystemNotDefined,
      "Please install #{using_gem(klass)} gem."
  end
end
check_settings(*required_values) click to toggle source

Check API credentials were given. If one is missing or empty it will raise error.

@param [List] required_values a comma separated values/symbols

# File lib/t/mailer/helper.rb, line 18
def check_settings(*required_values)
  has_all_settings =
    settings.values_at(*required_values).all? do |setting|
      setting && !setting.empty?
    end

  unless settings.is_a?(Hash) && has_all_settings
    fail Error::MissingCredentials,
      "Please provide all credential values. Required: #{required_values}"
  end
end
check_version_of(gem_name, version) click to toggle source

Check the version of a gem.

@param [String] gem_name the name of the gem @param [String] version the satisfied version of the gem

@return [Boolean] true/false

# File lib/t/mailer/helper.rb, line 36
def check_version_of(gem_name, version)
  requirement     = Gem::Requirement.new(version)
  current_version = Gem.loaded_specs[gem_name].version

  requirement.satisfied_by?(current_version)
end
field_value() click to toggle source

How to gets the uparsed value of the mail message fields.

@return [String] version dependent method call

# File lib/t/mailer/helper.rb, line 46
def field_value
  if check_version_of("mail", "> 2.7.0")
    %w(unparsed_value)
  elsif check_version_of("mail", "= 2.7.0")
    %w(instance_variable_get @unparsed_value)
  elsif check_version_of("mail", "< 2.7.0")
    %w(instance_variable_get @value)
  end
end
get_value_from(message_field) click to toggle source

Gets uparsed value of the mail message fields.

@param [Mail::Field] message_field

@return [String/Hash] with the field unparsed value

# File lib/t/mailer/helper.rb, line 61
def get_value_from(message_field)
  return if message_field.nil?

  message_field.public_send(*field_value)
end
using_gem(klass) click to toggle source

Which gem using an API class.

@param [String] klass the class name

@return [String] the gem name which should use

# File lib/t/mailer/helper.rb, line 72
def using_gem(klass)
  case klass
  when "Api::AwsSes"
    "aws-sdk-ses"
  when "Api::SparkPost::Transmissions"
    "simple_spark"
  else
    "unknown"
  end
end