Module: Policy::Follower::ClassMethods
- Included in:
- Policy::Follower
- Defined in:
- lib/policy/follower.rb
Overview
Methods to be added to the class the module is included to
Instance Attribute Summary collapse
-
#followed_policies ⇒ Policy::Follower::FollowedPolicies
readonly
The collection of policies to be followed by instances of the class.
Instance Method Summary collapse
-
#follow_policy(policy, *attributes, as: nil) ⇒ undefined
Adds a policy to the list of #followed_policies.
-
#use_policies(namespace) { ... } ⇒ undefined
Changes the namespace for applied policies.
Instance Attribute Details
#followed_policies ⇒ Policy::Follower::FollowedPolicies (readonly)
The collection of policies to be followed by instances of the class
23 24 25 |
# File 'lib/policy/follower.rb', line 23 def followed_policies @followed_policies ||= FollowedPolicies.new end |
Instance Method Details
#follow_policy(policy, *attributes, as: nil) ⇒ undefined
Adds a policy to the list of #followed_policies
39 40 41 42 |
# File 'lib/policy/follower.rb', line 39 def follow_policy(policy, *attributes, as: nil) object = FollowedPolicy.new(__policies__, policy, as, *attributes) followed_policies.add object end |
#use_policies(namespace) { ... } ⇒ undefined
Changes the namespace for applied policies
56 57 58 59 60 61 |
# File 'lib/policy/follower.rb', line 56 def use_policies(namespace, &block) @__policies__ = namespace instance_eval(&block) ensure @__policies__ = nil end |