Sha256: 6544809b73141794d8a7d0d893889319dceccb170034205f1fba1c3cc259524d

Contents?: true

Size: 866 Bytes

Versions: 3

Compression:

Stored size: 866 Bytes

Contents

module ApnClient
  class NamedArgs
    def self.assert_valid!(arguments, options)
      arguments ||= {}
      options[:optional] ||= []
      options[:required] ||= []
      assert_allowed!(arguments, options[:optional] + options[:required])
      assert_present!(arguments, options[:required])
    end

    def self.assert_allowed!(arguments, allowed_keys)
      invalid_keys = arguments.keys.select { |key| !allowed_keys.include?(key) }
      unless invalid_keys.empty?
        raise "Invalid arguments: #{invalid_keys.join(', ')}. Must be one of #{allowed_keys.join(', ')}"
      end
    end

    def self.assert_present!(arguments, required_keys)
      missing_keys = required_keys.select { |key| !arguments.keys.include?(key) }
      unless missing_keys.empty?
        raise "Missing required arguments: #{missing_keys.join(', ')}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
apn_client-0.0.3 lib/apn_client/named_args.rb
apn_client-0.0.2 lib/apn_client/named_args.rb
apn_client-0.0.1 lib/apn_client/named_args.rb