I'm trying to make a super generic class that when inherited from I can call a generic Sidekiq worker.
The idea would be to have all my services able to be called either normally or asynchronously. The problem is I would like to pass objects to the service but I can only pass pointers to the worker.
So if my service needs a User
and a String
I would currently have:
*args = [#<User:y6t4ert56uu6>, "I'm a string"]
For this to work I will need to make this array:
[{activerecord: true, class: "User", value: user_id}, {activerecord: false, class: "String", value: "I'm a string"}]
Once I know User
is an activerecord object I can safely assume there's an id
(presuming I'm only passing saved objects). Otherwise I would just output the value of the variable.
An idea of the perfect solution would be: (without the important code)
user = User.first
str = "Hello"
is_activerecord(user) # returns true
is_activerecord(str) # returns false
Can anyone suggest ideas on how to do this?
Thanks
some_object.class < ActiveRecord::Base
?Module#<
if you only care that there is anid
then why not justsome_object.respond_to?(:id)
.id
, but assumed it wasn't possible. Thanks for that!