Module: Queries::Concerns::Polymorphic

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

Instance Method Summary (collapse)

Instance Method Details

- (Arel::Node?) matching_polymorphic_ids

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

- (ActiveRecord object?) object_for

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

- (Object) set_polymorphic_ids(hash)



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