Module: TroleGroups::Api::Event

Defined in:
lib/trole_groups/api/event.rb

Instance Method Summary collapse

Instance Method Details

#field_changed?(name) ⇒ Boolean

check if a field on the model changed See api.rubyonrails.org/classes/ActiveModel/Dirty.html

Returns:

  • (Boolean)


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_groupsObject

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