Class: ParamsReady::Query::VariableOperatorPredicate
- Inherits:
-
Parameter::AbstractParameter
- Object
- Parameter::AbstractParameter
- ParamsReady::Query::VariableOperatorPredicate
- Defined in:
- lib/params_ready/query/variable_operator_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) ⇒ VariableOperatorPredicate
constructor
A new instance of VariableOperatorPredicate.
- #inspect_content ⇒ Object
- #operator ⇒ Object
- #perform_test(record, attribute_name) ⇒ Object
- #value ⇒ 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) ⇒ VariableOperatorPredicate
Returns a new instance of VariableOperatorPredicate.
13 14 15 16 |
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 13 def initialize(definition) super definition @data = definition.struct_parameter.create end |
Instance Method Details
#build_query(select_expression, context: nil) ⇒ Object
18 19 20 |
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 18 def build_query(select_expression, context: nil) operator.to_query(select_expression, value) end |
#inspect_content ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 34 def inspect_content op, val = if is_definite? @data[:operator].unwrap_or(nil)&.name || '?' @data[:value].unwrap_or('?') else %w[? ?] end "#{definition.attribute_name} #{op} #{val}" end |
#operator ⇒ Object
30 31 32 |
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 30 def operator @data[:operator].unwrap end |
#perform_test(record, attribute_name) ⇒ Object
22 23 24 |
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 22 def perform_test(record, attribute_name) operator.test(record, attribute_name, value) end |
#value ⇒ Object
26 27 28 |
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 26 def value @data[:value].unwrap end |