module AdsCommon::Utils
Public Class Methods
hash_keys_to_str(data)
click to toggle source
Converts all hash keys to strings.
# File lib/ads_common/utils.rb, line 33 def self.hash_keys_to_str(data) return nil if data.nil? return data.inject({}) do |result, (k, v)| result[k.to_s] = v result end end
hash_keys_to_sym(data)
click to toggle source
Converts all hash keys to symbols.
# File lib/ads_common/utils.rb, line 42 def self.hash_keys_to_sym(data) return nil if data.nil? return data.inject({}) do |result, (k, v)| result[k.to_sym] = v result end end
save_oauth2_token(filename, token)
click to toggle source
Updates file to include token details.
# File lib/ads_common/utils.rb, line 51 def self.save_oauth2_token(filename, token) config_data = {} if File.exist?(filename) config_data = YAML::load_file(filename) new_file_name = self.find_new_name(filename) File.rename(filename, new_file_name) end config_data[:authentication][:oauth2_token] = token File.open(filename, 'w') {|f| f.write(YAML::dump(config_data))} end
Private Class Methods
find_new_name(old_name)
click to toggle source
Returns an available filename for renaming a given file.
# File lib/ads_common/utils.rb, line 65 def self.find_new_name(old_name) counter = 0 begin filename = old_name + '.backup' + ((counter > 0) ? counter.to_s : '') counter += 1 end while File.exist?(filename) return filename end