observers

Good idea to access session in observer or not?

I want to log user's actions in my Ruby on Rails application. So far, I have a model observer that inserts logs to the database after updates and creates. In order to store which user performed the action that was logged, I require access to the session but that is problematic. Firstly, it breaks the MVC model. Secondly, techniques ran...

How do you efficiently implement the observer pattern if the subject is a huge container?

We all know the observer pattern: You have a subject which is able to notify and update a list of observers of its state changes. Now suppose that the subject you would like to observe is a container, and you would like to observe the container itself, i.e. element addition and deletion of elements, and also the contained elements, i.e. ...

Rails User model has_many activities (observer) but should also be observed

I'm running into an issue with an existing ActiveRecord::Observer model that records various Activities of a User the site. Everything was working really well, until I tried to observe the User class with the same Activity model that it uses to observe other models. Consider that: class Activity < ActiveRecord::Base belongs_to :user b...

How to use java.util.Observable from Javascript?

I'm building a Drupal module that integrates the "FileCatalyst" Java FTP applet with a standard Drupal form. I'm implementing a hook to submit the form when a file transfer completes. Currently I'm polling the applet with a setTimeout() call, but this method can miss changes of state if they happen too fast. However, the FileCatalyst ob...

Monitor database table for external changes from within Rails application

I'm integrating some non-rails-model tables in my Rails application. Everything works out very nicely, the way I set up the model is: class Change < ActiveRecord::Base establish_connection(ActiveRecord::Base.configurations["otherdb_#{RAILS_ENV}"]) set_table_name "change" end This way I can use the Change model for all existing re...

How to access old state values within datamapper observer?

I'm using dm-observer to observe my dm models, and I need to perform some actions based on state changes within the model. I've figured out that @state is used to store the updated state value, but I have not been able to figure out how to access the old state value. In the example below I've used "old_state", but obviously that does not...

How pass data to 'generic' observer? As arguments or as a single struct?

I am busy adding a generic observer mechanism to a legacy C++ application (using Visual Studio 2010, but not using .Net, so .Net delegates are out of the question). In the design I want to separate the application-specific part as much as possible from the generic observer mechanism. The most logical way of implementing observers seems...

Magento : How to retrieve option information from a bundled product?

I have a bundled Product that contains 3 virtual products as options. I have an observer that is listening to an event when an item is added to the cart and I'm having a hard time figuring out how to get the option information that I selected when looking at the product: the start of the observer looks like this: public function checkS...

Is this called "Circular Reference"?

Having the Observer pattern, we all know that based on its class diagram, the SUBJECT uses a reference to the OBSERVER. Meanwhile, the OBSERVER has a reference to SUBJECT in order to register or remove itself. Is this a "Circular Reference"? ...