Module: AppManager::FailSafeHelper
- Included in:
- FailSafe
- Defined in:
- lib/app_manager/fail_safe_helper.rb
Instance Method Summary collapse
Instance Method Details
#convert_ruby_hash_to_json(ruby_string) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/app_manager/fail_safe_helper.rb', line 3 def convert_ruby_hash_to_json(ruby_string) return nil if ruby_string.nil? || ruby_string.empty? json_string = ruby_string.dup json_string.gsub!(/([^:])=>([^:])/, '\1:\2') json_string.gsub!(/\bnil\b/, 'null') json_string.gsub!(/\btrue\b/, 'true') json_string.gsub!(/\bfalse\b/, 'false') json_string.gsub!(/,(\s*[}\]])/, '\1') json_string rescue => e nil end |
#safe_parse_json(value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/app_manager/fail_safe_helper.rb', line 22 def safe_parse_json(value) return nil if value.nil? || value.empty? begin json_string = convert_ruby_hash_to_json(value) return JSON.parse(json_string) if json_string rescue JSON::ParserError => e return nil end end |