module Troles::Common::Api::Event
Public Instance Methods
event_manager()
click to toggle source
@return [Trole::EventManager] The event manager singleton (class) to use to handle role events
# File lib/troles/common/api/event.rb, line 35 def event_manager Troles::Common::EventManager end
publish_change(event)
click to toggle source
Publishes change event to the EventManager
configured The EventManager
is notied of the even type and who (which instance) sent it @param [Symbol] the event
# File lib/troles/common/api/event.rb, line 29 def publish_change event send :invalidate_role_cache! if event == :roles event_manager.publish_change event, :from => self end
role_field_changed?(name)
click to toggle source
Check if a field on the model changed For Rails 3, See api.rubyonrails.org/classes/ActiveModel/Dirty.html @param [String] the field to test for change
# File lib/troles/common/api/event.rb, line 18 def role_field_changed? name begin send :"#{name}_changed?" rescue false end end
update_roles()
click to toggle source
A change to the roles of the user should be published to an event handler this can be used to update both the Role cache of the user and fx the RolePermit cache. A Role Groups listener can also subscribe to this event
# File lib/troles/common/api/event.rb, line 11 def update_roles publish_change(:roles) if role_field_changed?(troles_config.role_field) end