From f7e08a4ab8649f68b77ffd1029910e7747042f62 Mon Sep 17 00:00:00 2001 From: rfritzsche Date: Thu, 6 Jun 2024 10:02:41 +0200 Subject: [PATCH] Comply to rubocop --- Gemfile | 6 +++--- lib/schemacop/v3/array_node.rb | 1 + lib/schemacop/v3/node.rb | 12 ++++-------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index f24d66f..34c5261 100644 --- a/Gemfile +++ b/Gemfile @@ -5,10 +5,10 @@ gemspec # Development dependencies gem 'bundler' -gem 'rake' +gem 'colorize' gem 'minitest' gem 'minitest-reporters' -gem 'colorize' -gem 'rubocop', '1.24.1' gem 'pry' +gem 'rake' +gem 'rubocop', '1.24.1' gem 'simplecov', '0.21.2' diff --git a/lib/schemacop/v3/array_node.rb b/lib/schemacop/v3/array_node.rb index e00fe4b..9cc077b 100644 --- a/lib/schemacop/v3/array_node.rb +++ b/lib/schemacop/v3/array_node.rb @@ -150,6 +150,7 @@ def children def cast(value) return default unless value + value = parse_if_json(value, allowed_types: { Array => :array }) result = [] diff --git a/lib/schemacop/v3/node.rb b/lib/schemacop/v3/node.rb index 320eab7..abb68aa 100644 --- a/lib/schemacop/v3/node.rb +++ b/lib/schemacop/v3/node.rb @@ -192,25 +192,21 @@ def process_json(attrs, json) return json.as_json end - def parse_if_json(data, result: nil, allowed_types:) + def parse_if_json(data, allowed_types:, result: nil) if data.is_a?(String) data = JSON.parse(data) - if result - return nil unless validate_type(data, result, allowed_types: allowed_types) + if result && !validate_type(data, result, allowed_types: allowed_types) + return nil end end return data rescue JSON::ParserError => e - if result - result.error "JSON parse error: #{e.message.inspect}." - end - + result&.error "JSON parse error: #{e.message.inspect}." return nil end - def type_assertion_method :is_a? end