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, opts) ⇒ ResolverBuilder

Returns a new instance of ResolverBuilder.



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

def initialize(model, association, opts)
  @model = model
  @association = association
  @options = opts
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

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#association_class_nameObject



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

def association_class_name
  association.to_s.classify
end

#define_resolverObject



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

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

  model.const_set(resolver_class_name, resolver)

  resolver.validate!
end

#resolverObject



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

def resolver
  define_resolver unless model.const_defined?(resolver_class_name)

  model.const_get(resolver_class_name)
end

#resolver_class_nameObject



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

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