Module: GraphQL::Decorate::ObjectIntegration

Defined in:
lib/graphql/decorate/object_integration.rb

Overview

Extends GraphQL::Schema::Object classes with methods to set the desired decorator class and context.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#decorator_classClass? (readonly)

Returns Gets the currently set decorator class.

Returns:

  • (Class, nil)

    Gets the currently set decorator class.



29
30
31
# File 'lib/graphql/decorate/object_integration.rb', line 29

def decorator_class
  @decorator_class
end

#decorator_evaluatorProc? (readonly)

Returns Gets the currently set decorator evaluator.

Returns:

  • (Proc, nil)

    Gets the currently set decorator evaluator.



32
33
34
# File 'lib/graphql/decorate/object_integration.rb', line 32

def decorator_evaluator
  @decorator_evaluator
end

#decorator_metadataObject (readonly)

Returns the value of attribute decorator_metadata.



34
35
36
# File 'lib/graphql/decorate/object_integration.rb', line 34

def 
  @decorator_metadata
end

Class Method Details

.included(base) ⇒ nil

Parameters:

  • base (Class)

    Base class the module is being included in

Returns:

  • (nil)


9
10
11
# File 'lib/graphql/decorate/object_integration.rb', line 9

def self.included(base)
  base.extend(self)
end

Instance Method Details

#decorate_metadata {|object| ... } ⇒ Proc

Pass additional data to the decorator context (if supported).

Yields:

  • (object)

    Gives the underlying object to the block.

Returns:

  • (Proc)

    Proc to evaluate decorator context. Proc should return Hash.



23
24
25
26
# File 'lib/graphql/decorate/object_integration.rb', line 23

def 
  @decorator_metadata ||= GraphQL::Decorate::Metadata.new
  yield(@decorator_metadata)
end

#decorate_with(klass = nil, &block) ⇒ Object

Decorate the type with a decorator class.

Parameters:

  • klass (Class) (defaults to: nil)

    Class the object should be decorated with.



15
16
17
18
# File 'lib/graphql/decorate/object_integration.rb', line 15

def decorate_with(klass = nil, &block)
  @decorator_class = klass
  @decorator_evaluator = block
end