Module: MultiMail::Service
- Defined in:
- lib/multi_mail/service.rb
Overview
Interacts with email APIs to send or receive email.
Instance Method Summary collapse
-
#recognized ⇒ Array
Returns the list of optional arguments.
-
#recognizes(*args) ⇒ Object
Appends the given arguments to the list of optional arguments.
-
#requirements ⇒ Array
Returns the list of required arguments.
-
#requires(*args) ⇒ Object
Appends the given arguments to the list of required arguments.
-
#validate_options(options, raise_error_if_unrecognized = true) ⇒ Object
Ensures that required arguments are present and that optional arguments are recognized.
Instance Method Details
#recognized ⇒ Array
Returns the list of optional arguments.
34 35 36 |
# File 'lib/multi_mail/service.rb', line 34 def recognized @recognized ||= [] end |
#recognizes(*args) ⇒ Object
Appends the given arguments to the list of optional arguments.
26 27 28 |
# File 'lib/multi_mail/service.rb', line 26 def recognizes(*args) recognized.concat(args) end |
#requirements ⇒ Array
Returns the list of required arguments.
18 19 20 |
# File 'lib/multi_mail/service.rb', line 18 def requirements @requirements ||= [] end |
#requires(*args) ⇒ Object
Appends the given arguments to the list of required arguments.
10 11 12 |
# File 'lib/multi_mail/service.rb', line 10 def requires(*args) requirements.concat(args) end |
#validate_options(options, raise_error_if_unrecognized = true) ⇒ Object
Ensures that required arguments are present and that optional arguments are recognized.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/multi_mail/service.rb', line 45 def (, raise_error_if_unrecognized = true) keys = [] for key, value in unless value.nil? keys << key end end missing = requirements - keys unless missing.empty? raise ArgumentError, "Missing required arguments: #{missing.map(&:to_s).sort.join(', ')}" end if !recognizes.empty? && raise_error_if_unrecognized unrecognized = .keys - requirements - recognized unless unrecognized.empty? raise ArgumentError, "Unrecognized arguments: #{unrecognized.map(&:to_s).sort.join(', ')}" end end end |