Class: Policy::Follower::FollowedPolicy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/policy/follower/followed_policy.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.

Stores the policy to be applied to all instances of the follower

The policy object can be set either as a constant, or by name in given namespace. Namespace and policy name can be set separately.

The separation is used at the #apply_policies.

Examples:

The policy can be constant

FollowedPolicy.new nil, Foo::Bar::Baz, :baz_policy, :baz

The policy can be name, relative to the namespace

FollowedPolicy.new Foo::Bar, :Baz, :baz_policy, :baz
# Foo::Bar::Baz policy object will be used

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesArray<Symbol> (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 list of follower attributes to be send to the policy object

Returns:

  • (Array<Symbol>)


61
62
63
# File 'lib/policy/follower/followed_policy.rb', line 61

def attributes
  @attributes
end

#nameSymbol (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 name for the policy

Returns:

  • (Symbol)


49
50
51
# File 'lib/policy/follower/followed_policy.rb', line 49

def name
  @name
end

#policyClass (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 policy object class to be followed

Returns:

  • (Class)


55
56
57
# File 'lib/policy/follower/followed_policy.rb', line 55

def policy
  @policy
end

Class Method Details

.initialize(namespace, policy, name, *attributes) ⇒ Policy::Follower::FollowedPolicy

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 immutable policy to be followed by given object

Parameters:

  • namespace (Module)

    the namespace for the policy, given by name

  • policy (Class, #to_s)

    the class for applicable policy

  • name (#to_sym, nil)

    the name for the policy

  • attributes (Array<Symbol>)

    the list of follower attributes to apply the policy to

Returns:



39
40
41
42
43
# File 'lib/policy/follower/followed_policy.rb', line 39

def initialize(namespace, policy, name, *attributes)
  @policy     = find_policy(namespace, policy)
  @name       = (name || SecureRandom.uuid).to_sym
  @attributes = check_attributes attributes
end

Instance Method Details

#apply_to(follower) ⇒ undefined

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.

Applies the policy to follower instance

Parameters:

Returns:

  • (undefined)

Raises:



72
73
74
# File 'lib/policy/follower/followed_policy.rb', line 72

def apply_to(follower)
  policy.apply(*attributes_of(follower))
end

#new(namespace, policy, name, *attributes) ⇒ Policy::Follower::FollowedPolicy

Creates the immutable policy to be followed by given object

Parameters:

  • namespace (Module)

    the namespace for the policy, given by name

  • policy (Class, #to_s)

    the class for applicable policy

  • name (#to_sym, nil)

    the name for the policy

  • attributes (Array<Symbol>)

    the list of follower attributes to apply the policy to

Returns:



39
40
41
42
43
# File 'lib/policy/follower/followed_policy.rb', line 39

def initialize(namespace, policy, name, *attributes)
  @policy     = find_policy(namespace, policy)
  @name       = (name || SecureRandom.uuid).to_sym
  @attributes = check_attributes attributes
end