Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring a tiny portion of existing logic #356

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions lib/zendesk_apps_support/validations/requirements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,23 @@ module Requirements

class << self
def call(package)
if package.manifest.requirements_only? && !package.has_requirements?
return [ValidationError.new(:missing_requirements)]
elsif !supports_requirements(package) && package.has_requirements?
return [ValidationError.new(:requirements_not_supported)]
elsif !package.has_requirements?
unless package.has_requirements?
return [ValidationError.new(:missing_requirements)] \
if package.manifest.requirements_only?
mmassaki marked this conversation as resolved.
Show resolved Hide resolved

return []
end

return [ValidationError.new(:requirements_not_supported)] \
unless supports_requirements(package)
mmassaki marked this conversation as resolved.
Show resolved Hide resolved

begin
requirements = package.requirements_json
rescue ZendeskAppsSupport::Manifest::OverrideError => e
return [ValidationError.new(:duplicate_requirements, duplicate_keys: e.key, count: 1)]
end

[].tap do |errors|
errors << invalid_requirements_types(requirements)
errors << excessive_requirements(requirements)
errors << excessive_custom_objects_requirements(requirements)
errors << invalid_channel_integrations(requirements)
errors << invalid_custom_fields(requirements)
errors << invalid_custom_objects(requirements)
errors << invalid_webhooks(requirements)
errors << invalid_target_types(requirements)
errors << missing_required_fields(requirements)
errors.flatten!
errors.compact!
end
erros(requirements)
rescue JSON::ParserError => e
return [ValidationError.new(:requirements_not_json, errors: e)]
end
Expand Down Expand Up @@ -184,6 +174,22 @@ def invalid_target_types(requirements)
end
end
end

def erros(requirements)
mmassaki marked this conversation as resolved.
Show resolved Hide resolved
[].tap do |errors|
errors << invalid_requirements_types(requirements)
errors << excessive_requirements(requirements)
errors << excessive_custom_objects_requirements(requirements)
errors << invalid_channel_integrations(requirements)
errors << invalid_custom_fields(requirements)
errors << invalid_custom_objects(requirements)
errors << invalid_webhooks(requirements)
errors << invalid_target_types(requirements)
errors << missing_required_fields(requirements)
errors.flatten!
errors.compact!
end
end
end
end
end
Expand Down