Replacing the copy plugin for 3.0 - how to get the context?

19 views
Skip to first unread message

m...@catchandrelease.com

unread,
Jul 23, 2019, 5:14:31 PM7/23/19
to Shrine
Hi,

I'm working on replacing our usage of the copy plugin, but am running into an issue where the context that previously was populated, no longer is.

I'm using what's mentioned in this commit[1], but we override generate_location in our uploader, and the context in that override is now always
an empty hash. The line being replaced was literally dest.attacher.copy(source.attacher). No other setup was present.

How do I get context correctly populated again, without using the copy plugin?

Janko Marohnić

unread,
Jul 23, 2019, 6:05:39 PM7/23/19
to Shrine, m...@catchandrelease.com
Oh, right, I forgot about the context in that commit message. You can pass the context as the second argument to Shrine#upload:

  attacher.store.upload(other_attacher.get, attacher.context)
  attacher.set(copied_file)

Or use Attacher#store! which does it automatically:

  attacher.store!(other_attacher.get)
  attacher.set(copied_file)

Kind regards,
Janko
--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/0bc26370-a189-48d1-ac8b-54704bf5877d%40googlegroups.com.

MPD CANDR

unread,
Jul 24, 2019, 4:52:09 PM7/24/19
to Janko Marohnić, Shrine
Hi,

Thank you for getting back to me. Is anything additional required if the versions plugin is in use? We have several Shrine'd models, but one uses versions, and this doesn't look to work in that case.
The models that do not use versions work great now.

Janko Marohnić

unread,
Jul 24, 2019, 7:28:43 PM7/24/19
to MPD CANDR, Shrine
Doesn't work in what way? It would be very helpful if you could provide me with a self-contained script of what exactly you want to achieve but are not able to. That way I'll know for sure what is the goal how to make it work.

Kind regards,
Janko

MPD CANDR

unread,
Jul 24, 2019, 8:07:36 PM7/24/19
to Janko Marohnić, Shrine
I'm literally just wanting to replace dest.attacher.copy(source.attacher), except with the case of a versioned attachment.

The real problem I'm seeing with this is that validations no longer seem to work with versions. My Attacher.validate block
just gets the entire hash, so NoMethodError: undefined method `mime_type' for #<Hash:0x000055f1024b0570>, etc.

Outside of the validations, copying seems to work ok with versions.

Janko Marohnić

unread,
Jul 25, 2019, 3:42:37 AM7/25/19
to MPD CANDR, Shrine
Ok, yes, validations won't work with versions (in Shrine 3.0 this will be improved). For now you could just skip validations for versions:

  Attacher.validate do
    next if get.is_a?(Hash)

    # ...
  end

Kind regards,
Janko
Reply all
Reply to author
Forward
0 new messages