Module: Troles::Common::Api::Event
- Defined in:
- lib/troles/common/api/event.rb
Instance Method Summary collapse
-
#event_manager ⇒ Trole::EventManager
The event manager singleton (class) to use to handle role events.
-
#publish_change(event) ⇒ Object
Publishes change event to the EventManager configured The EventManager is notied of the even type and who (which instance) sent it.
-
#role_field_changed?(name) ⇒ Boolean
Check if a field on the model changed For Rails 3, See api.rubyonrails.org/classes/ActiveModel/Dirty.html.
-
#update_roles ⇒ Object
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.
Instance Method Details
#event_manager ⇒ Trole::EventManager
Returns The event manager singleton (class) to use to handle role events.
35 36 37 |
# File 'lib/troles/common/api/event.rb', line 35 def event_manager Troles::Common::EventManager end |
#publish_change(event) ⇒ Object
Publishes change event to the EventManager configured The EventManager is notied of the even type and who (which instance) sent it
29 30 31 32 |
# 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) ⇒ Boolean
Check if a field on the model changed For Rails 3, See api.rubyonrails.org/classes/ActiveModel/Dirty.html
18 19 20 21 22 23 24 |
# File 'lib/troles/common/api/event.rb', line 18 def role_field_changed? name begin send :"#{name}_changed?" rescue false end end |
#update_roles ⇒ Object
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
11 12 13 |
# File 'lib/troles/common/api/event.rb', line 11 def update_roles publish_change(:roles) if role_field_changed?(troles_config.role_field) end |