Class: Apiwork::Adapter::Builder::API::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/adapter/builder/api/base.rb

Overview

Base class for API-phase type builders.

API phase runs once per API at initialization time. Use it to register shared types used across all contracts.

Examples:

module Builder
  class API < Adapter::Builder::API::Base
    def build
      enum(:status, values: %w[active inactive])
      object(:error) do |object|
        object.string(:message)
      end
    end
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_class, data_type: nil) ⇒ Base

Returns a new instance of Base.



49
50
51
52
# File 'lib/apiwork/adapter/builder/api/base.rb', line 49

def initialize(api_class, data_type: nil)
  @api_class = api_class
  @data_type = data_type
end

Instance Attribute Details

#data_typeObject (readonly)



25
26
27
# File 'lib/apiwork/adapter/builder/api/base.rb', line 25

def data_type
  @data_type
end

Instance Method Details

#buildvoid

This method returns an undefined value.

Builds API-level types.

Override this method to register shared types.

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/apiwork/adapter/builder/api/base.rb', line 59

def build
  raise NotImplementedError
end

#enum(name, values:, **options, &block) ⇒ Object

See Also:



42
43
44
45
46
47
# File 'lib/apiwork/adapter/builder/api/base.rb', line 42

delegate :enum,
:enum?,
:object,
:type?,
:union,
to: :@api_class

#enum?(name) ⇒ Object

See Also:



42
43
44
45
46
47
# File 'lib/apiwork/adapter/builder/api/base.rb', line 42

delegate :enum,
:enum?,
:object,
:type?,
:union,
to: :@api_class

#object(name, **options, &block) ⇒ Object

See Also:



42
43
44
45
46
47
# File 'lib/apiwork/adapter/builder/api/base.rb', line 42

delegate :enum,
:enum?,
:object,
:type?,
:union,
to: :@api_class

#type?(name) ⇒ Object

See Also:



42
43
44
45
46
47
# File 'lib/apiwork/adapter/builder/api/base.rb', line 42

delegate :enum,
:enum?,
:object,
:type?,
:union,
to: :@api_class

#union(name, **options, &block) ⇒ Object

See Also:



42
43
44
45
46
47
# File 'lib/apiwork/adapter/builder/api/base.rb', line 42

delegate :enum,
:enum?,
:object,
:type?,
:union,
to: :@api_class