jhawthorn/discard

Documentation for un/discard is not completely correct

Closed this issue · 2 comments

# Discard the record in the database
#
# @return [Boolean] true if successful, otherwise false
def discard
return if discarded?

I think either these should return false if it's already discarded or the documentation should read "true if successful or a falsey value". Since the guard clause will make it return nil.

I can submit a PR if you want. Just let me know which option you like better. :)

just return true if discarded? imo, or:

    def discard
      discarded? || 
        run_callbacks(:discard) do
          update_attribute(self.class.discard_column, Time.current)
        end
    end

I kinda like the guard clause better, even though I also like having only a single return statement. But bool OR &block over 4 lines looks a bit weird to me.

I'll submit a PR soon!