module Strategize
  # A collection of policies.
  class PolicyGroup
    attr_reader :policies

    # Create a new PolicyGroup
    def initialize
      @policies = []
    end

    # Add policy to the group
    #
    # @param policy [Strategize::Policy] a class that includes the Policy module
    # @return [void]
    def add(policy)
      fail Strategize::NotPolicyError unless policy?(policy)
      @policies.push(policy)
    end

    private

    # Check if a policy includes the Policy module
    #
    # @private
    # @param policy [Class] the class to check
    def policy?(policy)
      policy.included_modules.include?(Policy)
    end
  end
end
