Sha256: 502c3fcbdd8fe5ece3067c05952f3998cdb88c3bc317fd8bb89227f124c8802c

Contents?: true

Size: 993 Bytes

Versions: 5

Compression:

Stored size: 993 Bytes

Contents

# encoding: utf-8

module Policy

  module Follower

    # Describes the list of followed policies
    #
    # @api private
    class FollowedPolicies < Hash

      # Registers followed policy with given unique key
      #
      # @param [Policy::Follower::FollowedPolicy] policy
      #
      # @return [undefined]
      def add(policy)
        self[policy.name] = policy
      end

      # Applies to follower the policies, selected by names
      #
      # @param [Policy::Follower] follower
      # @param [Array<#to_s>] names
      #
      # @raise [Policy::ViolationError]
      #   unless all policies are met
      #
      # @return [undefined]
      def apply_to(follower, *names)
        named_by(names).each { |policy| policy.apply_to(follower) }
      end

      private

      def named_by(list)
        names = Names.from list
        names.any? ? names.map(&method(:[])).compact : values
      end

    end # class FollowedPolicies

  end # module Follower

end # module Policy

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
policy-1.2.0 lib/policy/follower/followed_policies.rb
policy-1.1.0 lib/policy/follower/followed_policies.rb
policy-1.0.5 lib/policy/follower/followed_policies.rb
policy-1.0.4 lib/policy/follower/followed_policies.rb
policy-1.0.1 lib/policy/follower/followed_policies.rb