Class: GraphQL::AssociationBatchResolver::ResolverBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/association_batch_resolver/resolver_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, association) ⇒ ResolverBuilder

Returns a new instance of ResolverBuilder.



11
12
13
14
# File 'lib/graphql/association_batch_resolver/resolver_builder.rb', line 11

def initialize(model, association)
  @model = model
  @association = association
end

Instance Attribute Details

#associationObject

Returns the value of attribute association.



9
10
11
# File 'lib/graphql/association_batch_resolver/resolver_builder.rb', line 9

def association
  @association
end

#modelObject

Returns the value of attribute model.



9
10
11
# File 'lib/graphql/association_batch_resolver/resolver_builder.rb', line 9

def model
  @model
end

Instance Method Details

#association_class_nameObject



20
21
22
# File 'lib/graphql/association_batch_resolver/resolver_builder.rb', line 20

def association_class_name
  association.to_s.classify
end

#define_resolverObject



30
31
32
33
34
35
36
37
38
# File 'lib/graphql/association_batch_resolver/resolver_builder.rb', line 30

def define_resolver
  resolver = Class.new(AssociationResolver)
  resolver.model = model
  resolver.association = association

  model.const_set(resolver_class_name, resolver)

  resolver.validate!
end

#resolverObject



24
25
26
27
28
# File 'lib/graphql/association_batch_resolver/resolver_builder.rb', line 24

def resolver
  define_resolver unless model.const_defined?(resolver_class_name)

  model.const_get(resolver_class_name)
end

#resolver_class_nameObject



16
17
18
# File 'lib/graphql/association_batch_resolver/resolver_builder.rb', line 16

def resolver_class_name
  @resolver_class_name ||= "#{association_class_name}Resolver"
end