Module: Queries::Concerns::Polymorphic

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

Instance Method Summary collapse

Instance Method Details

#matching_polymorphic_idsArel::Node?

Returns:

  • (Arel::Node, nil)


38
39
40
41
42
43
44
45
46
# File 'lib/queries/concerns/polymorphic.rb', line 38

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)


28
29
30
31
32
33
34
# File 'lib/queries/concerns/polymorphic.rb', line 28

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

#set_polymorphic_ids(hash) ⇒ Object



22
23
24
25
# File 'lib/queries/concerns/polymorphic.rb', line 22

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