Module: AdsCommon::Utils
- Defined in:
- lib/ads_common/utils.rb
Defined Under Namespace
Modules: String
Class Method Summary collapse
-
.hash_keys_to_str(data) ⇒ Object
Converts all hash keys to strings.
-
.hash_keys_to_sym(data) ⇒ Object
Converts all hash keys to symbols.
-
.save_oauth2_token(filename, token) ⇒ Object
Updates file to include token details.
Class Method Details
.hash_keys_to_str(data) ⇒ Object
Converts all hash keys to strings.
33 34 35 36 37 38 39 |
# 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) ⇒ Object
Converts all hash keys to symbols.
42 43 44 45 46 47 48 |
# 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) ⇒ Object
Updates file to include token details.
51 52 53 54 55 56 57 58 59 60 |
# 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 |