Class: SimplePolicy::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_policy/entity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options, block) ⇒ Entity

Returns a new instance of Entity.



7
8
9
10
11
# File 'lib/simple_policy/entity.rb', line 7

def initialize(object, options, block)
  @object = object
  @options = options
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/simple_policy/entity.rb', line 5

def block
  @block
end

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/simple_policy/entity.rb', line 5

def object
  @object
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/simple_policy/entity.rb', line 5

def options
  @options
end

Class Method Details

.applies_to?(object, options = {}, &block) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/simple_policy/entity.rb', line 35

def self.applies_to?(object, options = {}, &block)
  call(object, options, block)
end

.applies_to_all?(collection, options = {}, &block) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/simple_policy/entity.rb', line 23

def self.applies_to_all?(collection, options = {}, &block)
  collection.all? do |object|
    applies_to?(object, options, &block)
  end
end

.applies_to_any?(collection, options = {}, &block) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/simple_policy/entity.rb', line 29

def self.applies_to_any?(collection, options = {}, &block)
  collection.any? do |object|
    applies_to?(object, options, &block)
  end
end

.call(*params, **options, &block) ⇒ Object



13
14
15
# File 'lib/simple_policy/entity.rb', line 13

def self.call(*params, **options, &block)
  new(*params, **options).call(&block)
end

.object_alias(name) ⇒ Object



17
18
19
20
21
# File 'lib/simple_policy/entity.rb', line 17

def self.object_alias(name)
  define_method(name) do
    object
  end
end