Class: ParamsReady::Query::PolymorphPredicate

Inherits:
Parameter::AbstractParameter show all
Includes:
ParamsReady::Query::Predicate::DelegatingPredicate, ParamsReady::Query::Predicate::HavingChildren
Defined in:
lib/params_ready/query/polymorph_predicate.rb

Instance Attribute Summary

Attributes included from ParamsReady::Query::Predicate::DelegatingPredicate

#data

Attributes inherited from Parameter::AbstractParameter

#definition

Instance Method Summary collapse

Methods included from ParamsReady::Query::Predicate::HavingChildren

#context_for_predicates

Methods included from ParamsReady::Query::Predicate::DelegatingPredicate

#eligible_for_query?, included, #to_query_if_eligible

Methods inherited from Parameter::AbstractParameter

#==, #dup, #inspect, intent_for_children, #match?, #populate, #to_hash, #update_if_applicable, #update_in

Methods included from Extensions::Freezer

#freeze_variable, #freeze_variables, #variables_to_freeze

Methods included from Parameter::FromHash

#set_from_hash

Methods included from Extensions::Freezer::InstanceMethods

#freeze

Constructor Details

#initialize(definition, **_) ⇒ PolymorphPredicate

Returns a new instance of PolymorphPredicate.



15
16
17
18
# File 'lib/params_ready/query/polymorph_predicate.rb', line 15

def initialize(definition, **_)
  super definition
  @data = definition.polymorph_parameter.create
end

Instance Method Details

#test(record) ⇒ Object



24
25
26
27
28
# File 'lib/params_ready/query/polymorph_predicate.rb', line 24

def test(record)
  return nil unless is_definite?

  data[data.type].test(record)
end

#to_query(arel_table, context: Restriction.blanket_permission) ⇒ Object



20
21
22
# File 'lib/params_ready/query/polymorph_predicate.rb', line 20

def to_query(arel_table, context: Restriction.blanket_permission)
  data[data.type].to_query_if_eligible(arel_table, context: context)
end