Class: Checkpoint::Resource::AllOfType

Inherits:
Checkpoint::Resource show all
Defined in:
lib/checkpoint/resource/all_of_type.rb

Overview

Specialized Resource type to represent all entities of a particular type.

Constant Summary

Constants inherited from Checkpoint::Resource

ALL

Instance Attribute Summary collapse

Attributes inherited from Checkpoint::Resource

#entity

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Checkpoint::Resource

all, #all_of_type, #token

Constructor Details

#initialize(type) ⇒ AllOfType

Create a wildcard Resource for a given type



9
10
11
# File 'lib/checkpoint/resource/all_of_type.rb', line 9

def initialize(type)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/checkpoint/resource/all_of_type.rb', line 7

def type
  @type
end

Class Method Details

.from(entity) ⇒ Object

Create a type-specific wildcard Resource from a given entity

When the entity implements to #to_resource, we convert it first and take the type from the result. Otherwise, when it implements #resource_type, we use that result. Otherwise, we take the class name of the entity. Regardless of the source, the type is forced to a string.



19
20
21
# File 'lib/checkpoint/resource/all_of_type.rb', line 19

def self.from(entity)
  new(type_of(entity))
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Compares with another Resource

Returns:

  • (Boolean)

    true if ‘other` is a Resource and its #type matches.



31
32
33
# File 'lib/checkpoint/resource/all_of_type.rb', line 31

def eql?(other)
  other.is_a?(Resource) && type == other.type
end

#idObject

This is always the special ALL resource ID



24
25
26
# File 'lib/checkpoint/resource/all_of_type.rb', line 24

def id
  Resource::ALL
end