Class: HQ::GraphQL::ObjectAssociation::ResourceReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/hq/graphql/object_association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, scope, options, macro, block) ⇒ ResourceReflection

Returns a new instance of ResourceReflection.



41
42
43
44
45
46
47
# File 'lib/hq/graphql/object_association.rb', line 41

def initialize(name, scope, options, macro, block)
  @name = name
  @scope = scope
  @options = options
  @macro = macro
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



39
40
41
# File 'lib/hq/graphql/object_association.rb', line 39

def block
  @block
end

#macroObject (readonly)

Returns the value of attribute macro.



39
40
41
# File 'lib/hq/graphql/object_association.rb', line 39

def macro
  @macro
end

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/hq/graphql/object_association.rb', line 39

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



39
40
41
# File 'lib/hq/graphql/object_association.rb', line 39

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



39
40
41
# File 'lib/hq/graphql/object_association.rb', line 39

def scope
  @scope
end

Instance Method Details

#reflection(model_klass) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/hq/graphql/object_association.rb', line 49

def reflection(model_klass)
  if macro == :has_many
    ::ActiveRecord::Associations::Builder::HasMany.create_reflection(model_klass, name, scope, options)
  elsif macro == :belongs_to
    ::ActiveRecord::Associations::Builder::BelongsTo.create_reflection(model_klass, name, scope, options)
  end
end