Module: Cuprum::Collections::Relation::Parameters

Included in:
Collection, Cuprum::Collections::Relation
Defined in:
lib/cuprum/collections/relation.rb

Overview

Methods for resolving a relations’s naming and entity class from options.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameString (readonly)

Returns the name of the relation.

Returns:

  • (String)

    the name of the relation.



311
312
313
# File 'lib/cuprum/collections/relation.rb', line 311

def name
  @name
end

#plural_nameString (readonly)

Returns the pluralized name of the relation.

Returns:

  • (String)

    the pluralized name of the relation.



314
315
316
# File 'lib/cuprum/collections/relation.rb', line 314

def plural_name
  @plural_name
end

#qualified_nameString (readonly)

Returns a scoped name for the relation.

Returns:

  • (String)

    a scoped name for the relation.



317
318
319
# File 'lib/cuprum/collections/relation.rb', line 317

def qualified_name
  @qualified_name
end

#singular_nameString (readonly)

Returns the name of an entity in the relation.

Returns:

  • (String)

    the name of an entity in the relation.



320
321
322
# File 'lib/cuprum/collections/relation.rb', line 320

def singular_name
  @singular_name
end

Class Method Details

.resolve_parameters(entity_class: nil, singular_name: nil, name: nil, qualified_name: nil) ⇒ Hash

Helper method for resolving a Relation’s required parameters.

The returned Hash will define the :entity_class, :singular_name, :name, and :qualified_name keys.

Parameters:

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

    the class of entity represented by the relation.

  • singular_name (String) (defaults to: nil)

    the name of an entity in the relation.

  • name (String) (defaults to: nil)

    the name of the relation.

  • qualified_name (String) (defaults to: nil)

    a scoped name for the relation.

Returns:

  • (Hash)

    the resolved parameters.



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/cuprum/collections/relation.rb', line 164

def resolve_parameters(params) # rubocop:disable Metrics/MethodLength
  validate_parameters(**params)

  entity_class   = entity_class_from(**params)
  class_name     = entity_class_name(entity_class)
  name           = relation_name_from(**params, class_name: class_name)
  plural_name    = plural_name_from(**params, name: name)
  qualified_name = qualified_name_from(**params, class_name: class_name)
  singular_name  = singular_name_from(**params, name: name)

  {
    entity_class:   entity_class,
    name:           name,
    plural_name:    plural_name,
    qualified_name: qualified_name,
    singular_name:  singular_name
  }
end

Instance Method Details

#entity_classClass

Returns the class of entity represented by the relation.

Returns:

  • (Class)

    the class of entity represented by the relation.



323
324
325
326
327
# File 'lib/cuprum/collections/relation.rb', line 323

def entity_class
  return @entity_class if @entity_class.is_a?(Class)

  @entity_class = Object.const_get(@entity_class)
end

#resolve_parameters(entity_class: nil, singular_name: nil, name: nil, qualified_name: nil) ⇒ Hash

Helper method for resolving a Relation’s required parameters.

The returned Hash will define the :entity_class, :singular_name, :name, and :qualified_name keys.

Parameters:

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

    the class of entity represented by the relation.

  • singular_name (String) (defaults to: nil)

    the name of an entity in the relation.

  • name (String) (defaults to: nil)

    the name of the relation.

  • qualified_name (String) (defaults to: nil)

    a scoped name for the relation.

Returns:

  • (Hash)

    the resolved parameters.



330
331
332
# File 'lib/cuprum/collections/relation.rb', line 330

def resolve_parameters(parameters)
  Parameters.resolve_parameters(parameters)
end