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.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#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(params, 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(params, 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 47 |
# File 'lib/entity_events.rb', line 26 def initialize(params,current_user) @params = params @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 |
#params ⇒ Object (readonly)
Returns the value of attribute params.
24 25 26 |
# File 'lib/entity_events.rb', line 24 def params @params 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.
77 78 79 |
# File 'lib/entity_events.rb', line 77 def controller params[:controller] end |
#default_actor ⇒ Object
89 90 91 |
# File 'lib/entity_events.rb', line 89 def default_actor current_user end |
#default_target ⇒ Object
93 94 95 96 |
# File 'lib/entity_events.rb', line 93 def default_target id = params["#{params[:controller].to_s.singularize}_id"] || params[:id] params[:controller].classify.constantize.find id if id end |
#event_class ⇒ Object
60 61 62 |
# File 'lib/entity_events.rb', line 60 def event_class self.class.name end |
#flag ⇒ Object
85 86 87 |
# File 'lib/entity_events.rb', line 85 def flag params[:flag] end |
#record ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/entity_events.rb', line 49 def record Interaction.log({ actor: actor, target: target, action: action, controller: controller, parameters: YAML::dump(params), flag: flag }) end |
#should_record? ⇒ Boolean
if auto_log == false, then should_record? will dictate is the action is recorded
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/entity_events.rb', line 65 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 |