Module: Policy::Follower

Defined in:
lib/policy/follower.rb,
lib/policy/follower/policies.rb,
lib/policy/follower/name_error.rb,
lib/policy/follower/violation_error.rb

Overview

Interface for the class that follows policies

Defined Under Namespace

Modules: ClassMethods Classes: NameError, Policies, ViolationError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



87
88
89
# File 'lib/policy/follower.rb', line 87

def self.included(klass)
  klass.instance_eval { extend ClassMethods }
end

Instance Method Details

#follow_policies?true #follow_policies?(names) ⇒ true

Checks whether an object follows all its policies or subset of policies

Overloads:

  • #follow_policies?true

    Checks whether an object follows all registered policies

  • #follow_policies?(names) ⇒ true

    Checks whether an object follows given policies

    Parameters:

    • names (#to_sym, Array<#to_sym>)

    Raises:

Returns:

  • (true)

    if no exception being raised

Raises:

  • (NoMethodError)

    if the name not implemented as follower’s instance method

  • (ViolationError)

    if the policy is violated by the follower



66
67
68
69
70
71
72
# File 'lib/policy/follower.rb', line 66

def follow_policies?(*names)
  __policies__
    .subset(names)                       # raises NameError
    .map(&method(:__send__))             # raises NoMethodError
    .each(&method(:__validate_policy__)) # raises ViolationError
  true
end

#follow_policy?(name) ⇒ true

Checks whether an object follows given policy

Parameters:

  • name (#to_sym)

    the name of the policy to follow

Returns:

  • (true)

    if no exception being raised

Raises:

  • (NoMethodError)

    if the name not implemented as follower’s instance method

  • (ViolationError)

    if the policy is violated by the follower



82
83
84
# File 'lib/policy/follower.rb', line 82

def follow_policy?(name)
  follow_policies? name
end