From 182f997744abeb0c4466f098ef84687b7b0c12ba Mon Sep 17 00:00:00 2001 From: Stuart Frost Date: Thu, 16 Nov 2023 18:36:15 +0000 Subject: [PATCH] Fix reload macro to include method in docs (#499) Co-authored-by: Seth T --- src/granite/querying.cr | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/granite/querying.cr b/src/granite/querying.cr index d508d46a..b0aac259 100644 --- a/src/granite/querying.cr +++ b/src/granite/querying.cr @@ -154,21 +154,19 @@ module Granite::Querying end end - {% if parse_type("Spec").resolve? %} - # Returns the record with the attributes reloaded from the database. - # - # **Note:** this method is only defined when the `Spec` module is present. - # - # ``` - # post = Post.create(name: "Granite Rocks!", body: "Check this out.") - # # record gets updated by another process - # post.reload # performs another find to fetch the record again - # ``` - def reload - {% if !@top_level.has_constant? "Spec" %} - raise "#reload is a convenience method for testing only, please use #find in your application code" - {% end %} - self.class.find!(primary_key_value) - end - {% end %} + # Returns the record with the attributes reloaded from the database. + # + # **Note:** this method is only defined when the `Spec` module is present. + # + # ``` + # post = Post.create(name: "Granite Rocks!", body: "Check this out.") + # # record gets updated by another process + # post.reload # performs another find to fetch the record again + # ``` + def reload + {% if !@top_level.has_constant? "Spec" %} + raise "#reload is a convenience method for testing only, please use #find in your application code" + {% end %} + self.class.find!(primary_key_value) + end end