Equivalent to Django Signals for Rails?

In Rails, the closest I saw was Django Signals : Watchers . The problem with them is that they cannot trigger callbacks for hard-coded events related to the life cycle of the model.

Django signals can be generated anywhere, triggered anywhere and processed anywhere. Model lifecycle callbacks are just regular signals that happen to be embedded and triggered by ORM.

Does anyone know of a similar general solution for Rails? It could be some common Ruby library not tied to Rails, which would be even better.


Edit: An observer is the closest, but that is not what I am looking for. This is a one-to-many solution. Anyone can listen, but only the source object can post messages. I would like you to announce a signal, and anyone can call it, as well as process it. Also, I don't like the fact that the Ruby Observer dictates that the handler has the #update method. I would like to be able to pass any reference to the method with the appropriate signature.

I could use the Ruby Observer to implement my own such broker, but I'm trying to find out if someone has already done this.

+3
source share
5 answers

, , Rails Observer, Ruby Observable. , .

+3

'wisper'? https://github.com/krisleech/wisper

Wisper - Ruby Ruby Pub/Sub.

ActiveRecord .

+1

, action_as_state. Rails-.

0

Ruby gem "watchable" - https://github.com/jbarnette/watchable

It has syntax that is very familiar to Django (and other frameworks such as Qt and many others).

0
source

Source: https://habr.com/ru/post/1714660/


All Articles