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.



36
37
38
39
40
41
42
# File 'lib/hq/graphql/object_association.rb', line 36

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.



34
35
36
# File 'lib/hq/graphql/object_association.rb', line 34

def block
  @block
end

#macroObject (readonly)

Returns the value of attribute macro.



34
35
36
# File 'lib/hq/graphql/object_association.rb', line 34

def macro
  @macro
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/hq/graphql/object_association.rb', line 34

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



34
35
36
# File 'lib/hq/graphql/object_association.rb', line 34

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



34
35
36
# File 'lib/hq/graphql/object_association.rb', line 34

def scope
  @scope
end

Instance Method Details

#reflection(model_klass) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/hq/graphql/object_association.rb', line 44

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