Module: T::Mailer::Helper
- Included in:
- Api::AwsSes, Api::SparkPost::Transmissions, DeliveryMethod, DeliverySystem::AwsSes, DeliverySystem::SparkPost
- Defined in:
- lib/t/mailer/helper.rb
Instance Method Summary collapse
-
#check_api_defined(klass) ⇒ Object
Check gem is installed or not.
-
#check_settings(*required_values) ⇒ Object
Check API credentials were given.
-
#check_version_of(gem_name, version) ⇒ Boolean
Check the version of a gem.
-
#field_value ⇒ String
How to gets the uparsed value of the mail message fields.
-
#get_value_from(message_field) ⇒ String/Hash
Gets uparsed value of the mail message fields.
-
#using_gem(klass) ⇒ String
Which gem using an API class.
Instance Method Details
#check_api_defined(klass) ⇒ Object
Check gem is installed or not. If not it will raise error.
7 8 9 10 11 12 |
# 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) ⇒ Object
Check API credentials were given. If one is missing or empty it will raise error.
18 19 20 21 22 23 24 25 26 27 28 |
# 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) ⇒ Boolean
Check the version of a gem.
36 37 38 39 40 41 |
# 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 ⇒ String
How to gets the uparsed value of the mail message fields.
46 47 48 49 50 51 52 53 54 |
# 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) ⇒ String/Hash
Gets uparsed value of the mail message fields.
61 62 63 64 65 |
# File 'lib/t/mailer/helper.rb', line 61 def get_value_from() return if .nil? .public_send(*field_value) end |
#using_gem(klass) ⇒ String
Which gem using an API class.
72 73 74 75 76 77 78 79 80 81 |
# 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 |