module SocialMan::ActionSubject::InstanceMethods
Public Instance Methods
active_to?(action_object, action_type = 'Action')
click to toggle source
# File lib/social_man/action_subject.rb, line 22 def active_to?(action_object, action_type = 'Action') Action.exists? action_type: action_type, action_subject: self, action_object: action_object end
method_missing(method_name, *args)
click to toggle source
objects_prefix
Calls superclass method
# File lib/social_man/action_subject.rb, line 64 def method_missing(method_name, *args) action_type, object_class = find_object_class method_name.to_s if object_class.nil? super else ids = active_actions.where(action_type: action_type).pluck(:action_object_id) object_class.where id: ids end end
take_action_on(action_object, action_type = 'Action')
click to toggle source
# File lib/social_man/action_subject.rb, line 18 def take_action_on(action_object, action_type = 'Action') Action.create action_type: action_type, action_subject: self, action_object: action_object end
undo_action_on(action_object, action_type = 'Action')
click to toggle source
# File lib/social_man/action_subject.rb, line 26 def undo_action_on(action_object, action_type = 'Action') Action.where(action_type: action_type, action_subject: self, action_object: action_object) .destroy_all end
Private Instance Methods
find_object_class(method_name)
click to toggle source
# File lib/social_man/action_subject.rb, line 77 def find_object_class(method_name) action_type = '' object_type = nil SocialMan.actions.each do |action| if method_name.start_with? action.objects_prefix action_type = action.type object_name = method_name.remove action.objects_prefix object_type = object_name.singularize.camelize unless object_name.blank? break end end [action_type, object_type&.constantize] end