You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: user_behavior.rb
    path of file: ./repos/gdpr_rails/app/models/policy_manager/concerns
    
    the code of the file until where you have to start completion: # -*- encoding : utf-8 -*-
module PolicyManager::Concerns::UserBehavior
  extend ActiveSupport::Concern

  included do
    has_many :user_terms, class_name: "PolicyManager::UserTerm", autosave: true, foreign_key: :user_id, inverse_of: :user
    has_many :terms, through: :user_terms, class_name: "PolicyManager::Term", foreign_key: :user_id, inverse_of: :user
    has_many :portability_requests, class_name: "PolicyManager::PortabilityRequest", foreign_key: :user_id, inverse_of: :user

    # adds policies
    PolicyMan
    
  def pending_policies
    # TODO: this seems to be a litle inefficient, 
    # hint: try to do this in one query
    PolicyManager::Config.rules.select do |c|
      self.needs_policy_confirmation_for?(c.name)
    end
  end

  def pending_blocking_policies
    PolicyManager::Config.rules.select do |c|
      c.blocking && self.needs_policy_confirmation_for?(c.name)
    end
  end

  def confirm_all_policies!
    pending_policies.each do |c|
      term = c.terms.last
      self.handle_policy_for(term).accept!
    end
  end

  def reject_all_policies!
    pending_policies.each do |c|
      term = c.terms.last
      self.handle_policy_for(term).reject!
    end
  end

  def needs_policy_confirmation_for?(rule)
    term = policy_term_on(rule)
    user_term = policy_user_term_on(term)
    return true if user_term.blank?
    return true if user_term.rejected?
    term.created_at > user_term.created_at
  end

  def policy_term_on(rule)
    category = PolicyManager::Config.rules.find{|o| o.name == rule}
    #binding.pry if category.blank?
    term = category.terms.where(state: "published").last
    raise "no term for #{rule} policy" if term.blank?
    term
  end

  def policy_user_term_on(term)
    return if term.blank?
    self.user_terms.where(term_id: term.id).first
  end

  def handle_policy_for(term)
    self.user_terms.where(term_id: term).first_or_initialize do |member|
      member.term_id = term.id
    end
  end

  def can_request_portability?
    self.portability_requests.select{|p| p.pending? || p.progress?}.blank?
  end

  def accept_policy_from(name)
    term = PolicyManager::Config.rules.find{|o| o.name == name}.terms.published.last
    if term.present?
      user_term = self.handle_policy_for(term)
      user_term.accept! unless user_term.accepted?
    end
  end