Class: Policy::Follower::Policies Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#followerClass (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

Returns:

  • (Class)


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

Parameters:

  • follower (Class)

Returns:



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

Examples:

Policies.new.add("some_policy")

Parameters:

  • policy (#to_sym)

Returns:

  • (self)

    itself



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

Yield Parameters:

  • the (Symbol)

    name of the registered policy

Returns:

  • (Enumerator)


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

Parameters:

  • name (Symbol)

Returns:

  • (true)

Raises:

  • (Policy::Followers::NameError)

    if the name not registered yet



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

Parameters:

  • follower (Class)

Returns:



20
21
22
23
# File 'lib/policy/follower/policies.rb', line 20

def initialize(follower)
  @follower = follower
  @names = []
end

#subsetself #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

Overloads:

  • #subsetself

    Returns itself.

    Returns:

    • (self)

      itself

  • #subset(*names) ⇒ Policy::Follower::Policies

    Examples:

    policies = Policies.new(follower, %i(foo bar baz))
    policies.subset(:baz, :foo)
    # => #<Policies @names=[:baz, :foo]>

    Parameters:

    • names (Symbol, Array<Symbol>)

    Raises:

Returns:



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