zimbatm asked:

How can I add triggers to an Og entity ?

Is it possible to have trigger before or after a database operation occurs ?

Given the following code, how would you output some text on creation and deletion of an object ?

class User
  prop_accessor :login
  prop_accessor :password
end

(1 attempts)

zimbatm answered:

class User
  include ::Aspects

  prop_accessor :login
  prop_accessor :password

  before :print_password, :on => [:og_insert, :og_update]
  after  :print_bye, :on [:og_delete]

protected

  def print_password
    puts @password
  end
 
  def print_bye
    puts "bye #{@login}"
  end
end

The presented solution uses Glue::Aspect. I couldn't find any reliable doc about this. If you want more infos, try grep -r before . in your og directory.

Rating: 4