Sha256: 0b101456990411a500e1cba6f3112f08cbfab7f06ac6ccd288b4794b04b7f6c4

Contents?: true

Size: 415 Bytes

Versions: 1

Compression:

Stored size: 415 Bytes

Contents

module Alberich
  class EntityTargetObserver < ActiveRecord::Observer
    observe Alberich.user_class.underscore.to_sym,  Alberich.user_group_class.underscore.to_sym

    def after_save(obj)
      entity = Entity.find_or_create_for_target(obj)
      entity.name = obj.to_s
      entity.save!
    end

    def after_destroy(obj)
      entity = Entity.for_target(obj)
      entity.destroy if entity
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alberich-0.2.0 app/models/alberich/entity_target_observer.rb