class EntityEvents::EntityEvent
Attributes
action[R]
actor[R]
actor_is_user_defined[R]
current_user[R]
request[R]
target[R]
target_is_user_defined[R]
Public Class Methods
new(request, current_user)
click to toggle source
# File lib/entity_events.rb, line 26 def initialize(request, current_user) @request = request @action = action @current_user = current_user actor_method = (@action.to_s+'_actor').to_sym @actor = if respond_to?(actor_method) @actor_is_user_defined = true send actor_method else default_actor end target_method = (@action.to_s+'_target').to_sym @target = if respond_to?(target_method) @target_is_user_defined = true send target_method else default_target end end
Public Instance Methods
controller()
click to toggle source
You can override methods after this line, however it is not nessisary.
# File lib/entity_events.rb, line 75 def controller request.filtered_parameters[:controller] end
default_actor()
click to toggle source
# File lib/entity_events.rb, line 87 def default_actor current_user end
default_target()
click to toggle source
# File lib/entity_events.rb, line 91 def default_target id = request.filtered_parameters["#{request.filtered_parameters[:controller].to_s.singularize}_id"] || request.filtered_parameters[:id] request.filtered_parameters[:controller].classify.split(':').last.constantize.find id if id end
event_class()
click to toggle source
# File lib/entity_events.rb, line 58 def event_class self.class.name end
flag()
click to toggle source
# File lib/entity_events.rb, line 83 def flag request.filtered_parameters[:flag] end
record()
click to toggle source
# File lib/entity_events.rb, line 48 def record Interaction.log({ actor: actor, target: target, action: action, controller: controller, flag: flag, request_ip: request.remote_ip }) end
should_record?()
click to toggle source
if auto_log == false, then should_record? will dictate is the action is recorded
# File lib/entity_events.rb, line 63 def should_record? action_method = (@action.to_s+'?').to_sym if respond_to?(action_method) #if <action>? is defined follow that send action_method else #else if actor or target is defined, assume we are to record actor_is_user_defined || target_is_user_defined end end