Class: Azeroth::ResourceBuilder Private

Inherits:
Sinclair::Model
  • Object
show all
Defined in:
lib/azeroth/resource_builder.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.

Builder responsible for for building the resource methods

The builder adds 2 methods, one for listing all entries of a resource, and one for fetching an specific entry

Author:

  • Darthjee

Instance Method Summary collapse

Constructor Details

#initialize(model: , builder: , options: ) ⇒ ResourceBuilder

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.

Parameters:

  • model (Model) (defaults to: )

    Resource model interface

  • builder (Sinclair) (defaults to: )

    method builder

  • options (Azeroth::Options) (defaults to: )

    options



21
# File 'lib/azeroth/resource_builder.rb', line 21

initialize_with(:model, :builder, :options, writter: false)

Instance Method Details

#add_methodArray<Sinclair::MethodDefinition>

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.

Add a method to be build on the controller

Returns:

  • (Array<Sinclair::MethodDefinition>)


63
# File 'lib/azeroth/resource_builder.rb', line 63

delegate :name, :plural, to: :model

#appendArray<Sinclair::MethodDefinition>

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.

Append methods to be built to the builder

Methods are the listing of all entities and fetching of an specific entity

Returns:

  • (Array<Sinclair::MethodDefinition>)


29
30
31
32
33
34
35
# File 'lib/azeroth/resource_builder.rb', line 29

def append
  add_method(plural, "@#{plural} ||= #{model.klass}.all")
  add_method(
    name,
    "@#{name} ||= #{plural}.find_by!(#{id_key}: #{name}_id)"
  )
end

#builderSinclair

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.

Returns a method builder

Returns:

  • (Sinclair)

See Also:



55
# File 'lib/azeroth/resource_builder.rb', line 55

delegate :add_method, to: :builder

#modelModel

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.

Returns the model class of the resource

Returns:



# File 'lib/azeroth/resource_builder.rb', line 37


#nameString

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.

Returns the name of the resource represented by the model

Returns:

  • (String)


# File 'lib/azeroth/resource_builder.rb', line 64


#pluralSymbol

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.

key used to find a model. id by default

Returns:

  • (Symbol)


78
# File 'lib/azeroth/resource_builder.rb', line 78

delegate :id_key, to: :options