Class: ParameterSubstitution::Formatters::JsonParse

Inherits:
Base
  • Object
show all
Defined in:
lib/parameter_substitution/formatters/json_parse.rb

Class Method Summary collapse

Methods inherited from Base

key, parse_duration

Class Method Details

.descriptionObject



4
5
6
# File 'lib/parameter_substitution/formatters/json_parse.rb', line 4

def self.description
  "Attempts to parse strings as JSON. If valid, passes along the parsed object, if not valid json, or not a string, passes the json encoded value."
end

.encodingObject



12
13
14
# File 'lib/parameter_substitution/formatters/json_parse.rb', line 12

def self.encoding
  :json
end

.format(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/parameter_substitution/formatters/json_parse.rb', line 16

def self.format(value)
  if value.is_a?(String)
    JSON.parse(value)
    value
  else
    value.to_json
  end
rescue JSON::ParserError
  value.to_json
end

.has_parameters?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/parameter_substitution/formatters/json_parse.rb', line 8

def self.has_parameters?
  false
end