Skip to content

Commit

Permalink
Comply to rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoremo committed Jun 6, 2024
1 parent 51ea255 commit f7e08a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions lib/schemacop/v3/array_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def children

def cast(value)
return default unless value

value = parse_if_json(value, allowed_types: { Array => :array })

result = []
Expand Down
12 changes: 4 additions & 8 deletions lib/schemacop/v3/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f7e08a4

Please sign in to comment.