Class: SimpleActivity::ActivityProcessor
- Inherits:
-
Object
- Object
- SimpleActivity::ActivityProcessor
- Defined in:
- lib/simple_activity/services/activity_processor.rb
Instance Method Summary collapse
-
#initialize(controller, target = nil) ⇒ Object
constructor
This class is for internal usage.
-
#save ⇒ Object
Return nil at this level, but not at #initialize.
- #warning ⇒ Object
Constructor Details
#initialize(controller, target = nil) ⇒ Object
This class is for internal usage. No need to initialize this manually, instead use controller methods provided.
When being used as automatical way in controller, e.g. as after_filter, supply the controller
ActivityProcessor.new(self)
If cache options needs to be attached, ensure the second argument
ActivityProcessor.new(self, nil, foo: 'bar')
When being used manually, normally the target would be provided
ActivityProcessor.new(self, @article, foo: 'bar')
40 41 42 43 44 45 46 47 48 |
# File 'lib/simple_activity/services/activity_processor.rb', line 40 def initialize(controller, target=nil) @controller = controller @target = target ? target : get_target @target_type = @target.class.to_s @actor = get_actor @actor_type = @actor.class.to_s @action_key = @controller.action_name @cache = get_cache end |
Instance Method Details
#save ⇒ Object
Return nil at this level, but not at #initialize. The reason is not to throw error on ‘nil.create_activity`, for validation error of target is common case. SimpleActivity should let it pass.
53 54 55 56 57 58 59 60 61 |
# File 'lib/simple_activity/services/activity_processor.rb', line 53 def save if validate_attrs Activity.create(activity_attrs).tap do |activity| Callbacks.run_callbacks(activity) end else warning end end |
#warning ⇒ Object
63 64 65 66 |
# File 'lib/simple_activity/services/activity_processor.rb', line 63 def warning Rails.logger.warn "SimpleActivity: failed to create activity" nil end |