Class: Policy::Follower::Policies Private
- Inherits:
-
Object
- Object
- Policy::Follower::Policies
- Includes:
- Enumerable
- Defined in:
- lib/policy/follower/policies.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Collection of policy names to be followed
Instance Attribute Summary collapse
-
#follower ⇒ Class
readonly
private
The class that follows policies.
Class Method Summary collapse
-
.initialize(follower) ⇒ Policy::Follower::Policies
private
Creates the empty collection for the follower class.
Instance Method Summary collapse
-
#add(policy) ⇒ self
private
Adds the policy name to the list of followed policies.
-
#each {|the| ... } ⇒ Enumerator
private
Iterates through names of the policies.
-
#include?(name) ⇒ true
private
Checks whether the name is included to the #names.
-
#new(follower) ⇒ Policy::Follower::Policies
Creates the empty collection for the follower class.
-
#subset(*names) ⇒ Policy::Follower::Policies
private
Returns the subset of current collection.
Instance Attribute Details
#follower ⇒ Class (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The class that follows policies
90 91 92 |
# File 'lib/policy/follower/policies.rb', line 90 def follower @follower end |
Class Method Details
.initialize(follower) ⇒ Policy::Follower::Policies
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates the empty collection for the follower class
20 21 22 23 |
# File 'lib/policy/follower/policies.rb', line 20 def initialize(follower) @follower = follower @names = [] end |
Instance Method Details
#add(policy) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds the policy name to the list of followed policies
33 34 35 36 37 |
# File 'lib/policy/follower/policies.rb', line 33 def add(policy) name = policy.to_sym names << name unless names.include? name self end |
#each {|the| ... } ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterates through names of the policies
81 82 83 84 |
# File 'lib/policy/follower/policies.rb', line 81 def each return to_enum unless block_given? names.each { |name| yield(name) } end |
#include?(name) ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks whether the name is included to the #names
46 47 48 49 |
# File 'lib/policy/follower/policies.rb', line 46 def include?(name) fail(NameError.new(follower, name)) unless names.include?(name) true end |
#new(follower) ⇒ Policy::Follower::Policies
Creates the empty collection for the follower class
20 21 22 23 |
# File 'lib/policy/follower/policies.rb', line 20 def initialize(follower) @follower = follower @names = [] end |
#subset ⇒ self #subset(*names) ⇒ Policy::Follower::Policies
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the subset of current collection
68 69 70 71 72 73 74 |
# File 'lib/policy/follower/policies.rb', line 68 def subset(*names) return self unless names.flatten.any? policies = self.class.new(follower) valid(names).each(&policies.method(:add)) policies end |