File: utils.rb

package info (click to toggle)
ruby-fog-core 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 684 kB
  • sloc: ruby: 4,812; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Fog
  module Core
    module Utils
      # This helper prepares a Hash of settings for passing into {Fog::Service.new}.
      #
      # The only special consideration is if +:header+ key is passed in the contents are unchanged. This
      # allows the headers to be passed through to requests to customise HTTP headers without them being
      # broken by the +#to_sym+ calls.
      #
      # @param [Hash] settings The String based Hash to prepare
      # @option settings [Hash] :headers Passed to the underlying {Fog::Core::Connection} unchanged
      # @return [Hash]
      #
      def self.prepare_service_settings(settings)
        if settings.is_a? Hash
          copy = []
          settings.each do |key, value|
            obj = ![:headers].include?(key) ? prepare_service_settings(value) : value
            copy.push(key.to_sym, obj)
          end
          Hash[*copy]
        else
          settings
        end
      end
    end
  end
end