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.
21 22 23 24 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 21 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.
19 20 21 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 19 def default_value @default_value end |
#json_string ⇒ Object (readonly)
Returns the value of attribute json_string.
19 20 21 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 19 def json_string @json_string end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/json/safe_parse.rb', line 26 def call return default_value unless json_string.instance_of?(::String) begin ::JSON.parse(json_string) rescue default_value end end |