module SocialMan::ActionObject::InstanceMethods

Public Instance Methods

method_missing(method_name, *args) click to toggle source

subjects_prefix

Calls superclass method
# File lib/social_man/action_object.rb, line 64
def method_missing(method_name, *args)
  action_type, subject_class = find_subject_class method_name.to_s

  if subject_class.nil?
    super
  else
    ids = passive_actions.where(action_type: action_type).pluck(:action_subject_id)
    subject_class.where id: ids
  end
end
passive_to?(action_subject, action_type = 'Action') click to toggle source
# File lib/social_man/action_object.rb, line 22
def passive_to?(action_subject, action_type = 'Action')
  Action.exists? action_type: action_type, action_subject: action_subject, action_object: self
end
taken_action_by(action_subject, action_type = 'Action') click to toggle source
# File lib/social_man/action_object.rb, line 18
def taken_action_by(action_subject, action_type = 'Action')
  Action.create action_type: action_type, action_subject: action_subject, action_object: self
end
undo_action_by(action_subject, action_type = 'Action') click to toggle source
# File lib/social_man/action_object.rb, line 26
def undo_action_by(action_subject, action_type = 'Action')
  Action.where(action_type: action_type, action_subject: action_subject, action_object: self)
        .destroy_all
end

Private Instance Methods

find_subject_class(method_name) click to toggle source
# File lib/social_man/action_object.rb, line 77
def find_subject_class(method_name)
  action_type = ''
  subject_type = nil
  SocialMan.actions.each do |action|
    if method_name.start_with? action.subjects_prefix
      action_type = action.type
      subject_name = method_name.remove action.subjects_prefix
      subject_type = subject_name.singularize.camelize unless subject_name.blank?
      break
    end
  end

  [action_type, subject_type&.constantize]
end