Module: TroleGroups::Api::Event
- Defined in:
- lib/trole_groups/api/event.rb
Instance Method Summary collapse
-
#field_changed?(name) ⇒ Boolean
check if a field on the model changed See api.rubyonrails.org/classes/ActiveModel/Dirty.html.
-
#publish_change(event) ⇒ Object
can be customized here uses singleton EventManager.
-
#update_role_groups ⇒ 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
#field_changed?(name) ⇒ Boolean
check if a field on the model changed See api.rubyonrails.org/classes/ActiveModel/Dirty.html
12 13 14 |
# File 'lib/trole_groups/api/event.rb', line 12 def field_changed? name send :"#{name}_changed?" end |
#publish_change(event) ⇒ Object
can be customized here uses singleton EventManager
18 19 20 21 |
# File 'lib/trole_groups/api/event.rb', line 18 def publish_change event send :invalidate_rolegroups_cache! if event == :role_groups event_manager.publish_change event, :from => self end |
#update_role_groups ⇒ 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. Both (and potentially others, fx for Role Groups) can subscribe to this event!
6 7 8 |
# File 'lib/trole_groups/api/event.rb', line 6 def update_role_groups publish_change(:role_groups) if field_changed?(rolegroups_field) end |