Class: ParamsReady::Query::NullnessPredicate
- Inherits:
-
Parameter::AbstractParameter
- Object
- Parameter::AbstractParameter
- ParamsReady::Query::NullnessPredicate
- Defined in:
- lib/params_ready/query/nullness_predicate.rb
Instance Attribute Summary
Attributes included from Predicate::DelegatingPredicate
Attributes inherited from Parameter::AbstractParameter
Instance Method Summary collapse
- #build_query(select_expression, context: nil) ⇒ Object
-
#initialize(definition) ⇒ NullnessPredicate
constructor
A new instance of NullnessPredicate.
- #inspect_content ⇒ Object
- #perform_test(record, attribute_name) ⇒ Object
Methods included from Predicate::HavingAttribute
#context_for_predicates, #test, #to_query
Methods included from Predicate::HavingAssociations
Methods included from 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
Methods included from Extensions::Freezer::InstanceMethods
Constructor Details
#initialize(definition) ⇒ NullnessPredicate
Returns a new instance of NullnessPredicate.
10 11 12 13 |
# File 'lib/params_ready/query/nullness_predicate.rb', line 10 def initialize(definition) super definition @data = definition.value_parameter.create end |
Instance Method Details
#build_query(select_expression, context: nil) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/params_ready/query/nullness_predicate.rb', line 15 def build_query(select_expression, context: nil) query = select_expression.eq(nil) if !unwrap query.not else query end end |
#inspect_content ⇒ Object
34 35 36 |
# File 'lib/params_ready/query/nullness_predicate.rb', line 34 def inspect_content "#{definition.attribute_name} is_null? #{@data.inspect}" end |
#perform_test(record, attribute_name) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/params_ready/query/nullness_predicate.rb', line 24 def perform_test(record, attribute_name) if unwrap return true if record.nil? record.send(attribute_name).nil? else return false if record.nil? !record.send(attribute_name).nil? end end |