Class: Cuprum::Collections::Resource

Inherits:
Relation
  • Object
show all
Includes:
Cuprum::Collections::Relation::Cardinality, Cuprum::Collections::Relation::Disambiguation, Cuprum::Collections::Relation::PrimaryKeys
Defined in:
lib/cuprum/collections/resource.rb

Overview

Class representing a singular or plural resource of entities.

Direct Known Subclasses

Association

Instance Attribute Summary

Attributes inherited from Relation

#options

Attributes included from Cuprum::Collections::Relation::Parameters

#name, #plural_name, #qualified_name, #singular_name

Instance Method Summary collapse

Methods included from Cuprum::Collections::Relation::PrimaryKeys

#primary_key_name, #primary_key_type

Methods included from Cuprum::Collections::Relation::Disambiguation

disambiguate_keyword, #disambiguate_keyword, resolve_parameters, #resolve_parameters

Methods included from Cuprum::Collections::Relation::Cardinality

#plural?, #singular?

Methods included from Cuprum::Collections::Relation::Parameters

#entity_class, resolve_parameters, #resolve_parameters

Constructor Details

#initialize(entity_class: nil, name: nil, qualified_name: nil, singular_name: nil, **options) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • entity_class (Class, String) (defaults to: nil)

    the class of entity represented by the resource.

  • name (String) (defaults to: nil)

    the name of the resource. Aliased as :resource_name.

  • qualified_name (String) (defaults to: nil)

    a scoped name for the resource.

  • singular_name (String) (defaults to: nil)

    the name of an entity in the resource.

  • options (Hash)

    additional options for the resource.

Options Hash (**options):

  • plural (Boolean)

    if true, the resource represents a plural resource. Defaults to true. Can also be specified as :singular.

  • primary_key_name (String)

    the name of the primary key attribute. Defaults to ‘id’.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cuprum/collections/resource.rb', line 28

def initialize(**params)
  params  = disambiguate_keyword(params, :entity_class, :resource_class)
  params  = disambiguate_keyword(params, :name, :resource_name)
  params  = disambiguate_keyword(
    params,
    :singular_name,
    :singular_resource_name
  )
  @plural = resolve_plurality(**params)

  super(**params)
end

Instance Method Details

#resource_classClass

Returns the class of entity represented by the resource.

Returns:

  • (Class)

    the class of entity represented by the resource.



42
43
44
45
46
47
# File 'lib/cuprum/collections/resource.rb', line 42

def resource_class
  tools.core_tools.deprecate '#resource_class method',
    message: 'Use #entity_class instead'

  entity_class
end

#resource_nameString

Returns the name of the resource.

Returns:

  • (String)

    the name of the resource.



50
51
52
53
54
55
# File 'lib/cuprum/collections/resource.rb', line 50

def resource_name
  tools.core_tools.deprecate '#resource_name method',
    message: 'Use #name instead'

  name
end

#singular_resource_nameObject

@return the name of an entity in the resource.



58
59
60
61
62
63
# File 'lib/cuprum/collections/resource.rb', line 58

def singular_resource_name
  tools.core_tools.deprecate '#singular_resource_name method',
    message: 'Use #singular_name instead'

  singular_name
end