Class: EntityEvents::EntityEvent
- Inherits:
-
Object
- Object
- EntityEvents::EntityEvent
- Defined in:
- lib/entity_events.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#actor_is_user_defined ⇒ Object
readonly
Returns the value of attribute actor_is_user_defined.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#target_is_user_defined ⇒ Object
readonly
Returns the value of attribute target_is_user_defined.
Instance Method Summary collapse
-
#controller ⇒ Object
You can override methods after this line, however it is not nessisary.
- #default_actor ⇒ Object
- #default_target ⇒ Object
- #event_class ⇒ Object
- #flag ⇒ Object
-
#initialize(request, current_user) ⇒ EntityEvent
constructor
A new instance of EntityEvent.
- #record ⇒ Object
-
#should_record? ⇒ Boolean
if auto_log == false, then should_record? will dictate is the action is recorded.
Constructor Details
#initialize(request, current_user) ⇒ EntityEvent
Returns a new instance of EntityEvent.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def action @action end |
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def actor @actor end |
#actor_is_user_defined ⇒ Object (readonly)
Returns the value of attribute actor_is_user_defined.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def actor_is_user_defined @actor_is_user_defined end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def current_user @current_user end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def request @request end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def target @target end |
#target_is_user_defined ⇒ Object (readonly)
Returns the value of attribute target_is_user_defined.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def target_is_user_defined @target_is_user_defined end |
Instance Method Details
#controller ⇒ Object
You can override methods after this line, however it is not nessisary.
75 76 77 |
# File 'lib/entity_events.rb', line 75 def controller request.filtered_parameters[:controller] end |
#default_actor ⇒ Object
87 88 89 |
# File 'lib/entity_events.rb', line 87 def default_actor current_user end |
#default_target ⇒ Object
91 92 93 94 |
# 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 ⇒ Object
58 59 60 |
# File 'lib/entity_events.rb', line 58 def event_class self.class.name end |
#flag ⇒ Object
83 84 85 |
# File 'lib/entity_events.rb', line 83 def flag request.filtered_parameters[:flag] end |
#record ⇒ Object
48 49 50 51 52 53 54 55 56 |
# 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? ⇒ Boolean
if auto_log == false, then should_record? will dictate is the action is recorded
63 64 65 66 67 68 69 70 71 72 |
# 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 |