Module: Queries::Concerns::Polymorphic

Extended by:
ActiveSupport::Concern
Defined in:
lib/queries/concerns/polymorphic.rb

Instance Method Summary collapse

Instance Method Details

#global_object_idObject



39
40
41
# File 'lib/queries/concerns/polymorphic.rb', line 39

def global_object_id
  object_for&.id
end

#global_object_typeObject



43
44
45
46
47
48
49
# File 'lib/queries/concerns/polymorphic.rb', line 43

def global_object_type
  if object_for
    object_for&.class.name
  else
    nil
  end
end

#matching_polymorphic_idsArel::Node?

Returns:

  • (Arel::Node, nil)


53
54
55
56
57
58
59
60
61
# File 'lib/queries/concerns/polymorphic.rb', line 53

def matching_polymorphic_ids
  nodes = Queries::Annotator.polymorphic_nodes(polymorphic_ids, self.class.annotating_class)
  return nil if nodes.nil?
  a = nodes.shift
  nodes.each do |b|
    a = a.and(b)
  end
  a
end

#object_forActiveRecord object?

Returns:

  • (ActiveRecord object, nil)


31
32
33
34
35
36
37
# File 'lib/queries/concerns/polymorphic.rb', line 31

def object_for
  if @global_object = GlobalID::Locator.locate(object_global_id)
    @global_object
  else
    nil
  end
end

#set_polymorphic_ids(hash) ⇒ Object



25
26
27
28
# File 'lib/queries/concerns/polymorphic.rb', line 25

def set_polymorphic_ids(hash)
  @polymorphic_ids = hash.select{|k,v| self.class.annotating_class.related_foreign_keys.include?(k.to_s)} 
  @polymorphic_ids ||= {}
end