Clean up #not_nil! uses #84

Merged
dergrimm merged 1 commit from clean-up-not-nil into main 2022-03-07 10:04:42 +00:00
4 changed files with 7 additions and 8 deletions

View file

@ -50,7 +50,7 @@ module Backend
if @user
@admin = @user.not_nil!.admin
@role = Schema::UserRole.parse(@user.not_nil!.role).not_nil!
@role = Schema::UserRole.parse(@user.not_nil!.role)
@external =
case @role.not_nil!
when .teacher?

View file

@ -42,7 +42,7 @@ module Backend
end
def initialize(id : Int32)
@model = {{ type }}.find(id).not_nil!
@model = {{ type }}.find!(id)
end
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}
@ -50,7 +50,7 @@ module Backend
@[GraphQL::Field]
# {{ space_name }}'s ID
def id : Int32
@model.id.not_nil!.to_i32
@model.id.not_nil!.to_i
end
end
end

View file

@ -82,9 +82,9 @@ module Backend
@model.teacher
when .student?
@model.student
end.not_nil!.id.not_nil!.to_i
rescue NilAssertionError
nil
end
.try(&.id)
.try(&.to_i)
end
@[GraphQL::Field]

View file

@ -25,8 +25,7 @@ module Mosquito::Serializers::Granite
end
def deserialize_{{ method_suffix }}(raw : String) : {{ klass.id }}
id = raw.to_i
{{ klass.id }}.find(id).not_nil!
{{ klass.id }}.find!(raw.to_i)
end
end
end