On Wed, Dec 29, 2021 at 8:47 AM tr...@upserver24.com <tr...@upserver24.com>
wrote:

> Hi,
>
> We found this tiny useful plugin that allows to detect if model instance
> was just created:
>
> ```
> module Sequel
>   module Plugins
>     module JustCreated
>       module InstanceMethods
>         def after_create
>           @just_created = true
>           super
>         end
>
>         def just_created?
>           @just_created == true
>         end
>       end
>     end
>   end
> end
> ```
>
> I was trying to do it using :dirty plugin but didn't found a way, maybe I
> missing something? If not don't you mind if we create PR to include this
> plugin into sequel?
>

I don't think the dirty plugin supports this.  Could you explain the use
case for the plugin?  That would help me to better judge whether to include
it with Sequel.  Note that even if it isn't included with Sequel, it's easy
to ship as a external gem.

The plugin has at least one implementation issue:

Model.new.save.save.just_created? # => true, should be false, assuming you
want a object that hasn't been updated

Also, I'm not sure "just_created" is a good name.  After all:

m = Model.create
sleep(60*60*24)
m.just_created? # "just" generally implies recently.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSe075%3DMEDWKa7uQMuWXuUviCPyDGn8aOv_jDean0dOndg%40mail.gmail.com.

Reply via email to