Module: Policy::Follower

Extended by:
ClassMethods
Includes:
ActiveModel::Validations
Defined in:
lib/policy/follower.rb,
lib/policy/follower/names.rb,
lib/policy/follower/followed_policy.rb,
lib/policy/follower/followed_policies.rb

Overview

Adds features for the object to follow external policies

Defined Under Namespace

Modules: ClassMethods, Names Classes: FollowedPolicies, FollowedPolicy

Instance Method Summary collapse

Methods included from ClassMethods

follow_policy, use_policies

Instance Method Details

#follow_policies!(*names) ⇒ undefined

Checks whether an instance meets selected policies

Mutates the object by adding new #errors

Parameters:

  • names (Array<#to_sym>)

    the ordered list of names to select policies by when not names selected all policies will be applied

Returns:

  • (undefined)

Raises:



83
84
85
86
87
88
# File 'lib/policy/follower.rb', line 83

def follow_policies!(*names)
  followed_policies.apply_to self, *names
rescue ViolationError => error
  collect_errors_from(error)
  raise
end

#follow_policies?(*names) ⇒ Boolean

Safely checks whether an instance meets selected policies

Mutates the object by adding new #errors

Parameters:

  • names (Array<#to_sym>)

    the ordered list of names to select policies by when not names selected all policies will be applied

Returns:

  • (Boolean)


109
110
111
112
113
114
# File 'lib/policy/follower.rb', line 109

def follow_policies?(*names)
  follow_policies!(*names)
  true
rescue ViolationError
  false
end

#follow_policy!(name) ⇒ undefined

Syntax shugar for the #follow_policies! with one argument

Parameters:

  • name (#to_sym)

    the name of the policy to follow

Returns:

  • (undefined)

Raises:



98
99
100
# File 'lib/policy/follower.rb', line 98

def follow_policy!(name)
  follow_policies! name
end

#follow_policy?(name) ⇒ Boolean

Syntax shugar for the #follow_policies? with one argument

Parameters:

  • name (#to_sym)

    the name of the policy to follow

Returns:

  • (Boolean)


121
122
123
# File 'lib/policy/follower.rb', line 121

def follow_policy?(name)
  follow_policies? name
end