Module: Queries::Concerns::Polymorphic
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/queries/concerns/polymorphic.rb
Instance Method Summary collapse
- #global_object_id ⇒ Object
- #global_object_type ⇒ Object
-
#matching_polymorphic_ids ⇒ Arel::Node?
TODO: Dry with polymorphic_params.
- #object_for ⇒ ActiveRecord object?
-
#object_global_id_facet ⇒ Object
Not necessary, handled by splitting out id/type TODO: remove paradigm from Notes facets.
- #set_polymorphic_ids(hash) ⇒ Object
Instance Method Details
#global_object_id ⇒ Object
39 40 41 |
# File 'lib/queries/concerns/polymorphic.rb', line 39 def global_object_id object_for&.id end |
#global_object_type ⇒ Object
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.base_class.name else nil end end |
#matching_polymorphic_ids ⇒ Arel::Node?
TODO: Dry with polymorphic_params
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_for ⇒ ActiveRecord object?
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 |
#object_global_id_facet ⇒ Object
Not necessary, handled by splitting out id/type TODO: remove paradigm from Notes facets
65 66 67 68 69 70 71 72 |
# File 'lib/queries/concerns/polymorphic.rb', line 65 def object_global_id_facet return nil if object_global_id.nil? o = GlobalID::Locator.locate(object_global_id) k = o.class.base_class.name id = o.id t = self.class.annotating_class.table_name.singularize + '_object' table["#{t}_id".to_sym].eq(o.id).and(table["#{t}_type".to_sym].eq(k)) 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..include?(k.to_s)} @polymorphic_ids ||= {} end |