Class: ConvenientService::Examples::Standard::V1::RequestParams::Utils::JSON::SafeParse
- Inherits:
-
Command
- Object
- ConvenientService::Examples::Standard::V1::RequestParams::Utils::JSON::SafeParse
- Defined in:
- lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#json_string ⇒ Object
readonly
Returns the value of attribute json_string.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(json_string, default_value: nil) ⇒ SafeParse
constructor
A new instance of SafeParse.
Constructor Details
#initialize(json_string, default_value: nil) ⇒ SafeParse
Returns a new instance of SafeParse.
26 27 28 29 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 26 def initialize(json_string, default_value: nil) @json_string = json_string @default_value = default_value end |
Instance Attribute Details
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
24 25 26 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 24 def default_value @default_value end |
#json_string ⇒ Object (readonly)
Returns the value of attribute json_string.
24 25 26 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 24 def json_string @json_string end |
Instance Method Details
#call ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 31 def call return default_value unless json_string.instance_of?(::String) begin ::JSON.parse(json_string) rescue default_value end end |