Class: Apiwork::Adapter::Builder::Contract::Base

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

Overview

Base class for Contract-phase type builders.

Contract phase runs once per contract with representation at registration time. Use it to generate contract-specific types based on the representation.

Examples:

module Builder
  class Contract < Adapter::Builder::Contract::Base
    def build
      object(representation_class.root_key.singular.to_sym) do |object|
        object.string(:id)
        object.string(:name)
      end
    end
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contract_class, representation_class) ⇒ Base

Returns a new instance of Base.



69
70
71
72
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 69

def initialize(contract_class, representation_class)
  @contract_class = contract_class
  @representation_class = representation_class
end

Instance Attribute Details

#representation_classObject (readonly)



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

def representation_class
  @representation_class
end

Instance Method Details

#api_classObject

See Also:

  • Contract::Base.api_class


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

#buildvoid

This method returns an undefined value.

Builds contract-level types.

Override this method to generate types based on the representation.

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 79

def build
  raise NotImplementedError
end

#contract_for(representation_class) ⇒ Object

See Also:

  • Contract::Base.contract_for


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

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

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

#enum?(name) ⇒ Object

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

#import(type_name, from:) ⇒ Object

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

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

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

#scoped_enum_name(name) ⇒ Object

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

#scoped_type_name(name) ⇒ Object

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

#type?(name) ⇒ Object

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class

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

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apiwork/adapter/builder/contract/base.rb', line 57

delegate :api_class,
:contract_for,
:enum,
:enum?,
:import,
:object,
:scoped_enum_name,
:scoped_type_name,
:type?,
:union,
to: :@contract_class