Module: Integral::Yandex::Money::Helpers
- Included in:
- NotificationValidator
- Defined in:
- lib/integral/yandex/money/notification_validator/helpers.rb
Class Method Summary collapse
- .encode_sha(string) ⇒ Object
- .find_missing_hash_values(required_keys:, hash:) ⇒ Object
- .stringify_params_with_order(keys, params) ⇒ Object
- .validate_argument_type!(argument:, permitted_types:) ⇒ Object
Class Method Details
.encode_sha(string) ⇒ Object
13 14 15 |
# File 'lib/integral/yandex/money/notification_validator/helpers.rb', line 13 def encode_sha string Digest::SHA1.hexdigest string end |
.find_missing_hash_values(required_keys:, hash:) ⇒ Object
17 18 19 |
# File 'lib/integral/yandex/money/notification_validator/helpers.rb', line 17 def find_missing_hash_values required_keys:, hash: required_keys.select { |key| hash[key].to_s == "" } end |
.stringify_params_with_order(keys, params) ⇒ Object
21 22 23 24 |
# File 'lib/integral/yandex/money/notification_validator/helpers.rb', line 21 def stringify_params_with_order keys, params keys.map { |key| params[key] }.join("&") # this way and not just `.to_s` is to enforce required order of params end |
.validate_argument_type!(argument:, permitted_types:) ⇒ Object
26 27 28 29 30 |
# File 'lib/integral/yandex/money/notification_validator/helpers.rb', line 26 def validate_argument_type! argument:, permitted_types: names = permitted_types.map { |name| "`#{name}`" }.join(" or ") valid = permitted_types.include? argument.class.to_s fail ArgumentError, "`argument` must be a #{names}, you passed #{argument.inspect}" unless valid end |