Class: CriteriaOperator::BaseOperator Abstract
- Inherits:
-
Object
- Object
- CriteriaOperator::BaseOperator
- Defined in:
- lib/criteria_operator/base_operator.rb
Overview
Subclass and override #clone to implement.
Base class for all criteria operators. Provides operator overloads and other useful utility and convenience functions.
Direct Known Subclasses
BinaryOperator, GroupOperator, OperandProperty, OperandValue, UnaryOperator
Class Method Summary collapse
-
.deserialize(serialized_op) ⇒ BaseOperator
Deserializes an operator from a string.
-
.serialize(op) ⇒ String
Returns a string representation of an operator (including all sub-operators).
Instance Method Summary collapse
-
#clone ⇒ BaseOperator
abstract
Clones an operator with all sub-operators, creating a deep copy.
-
#serialize ⇒ String
Returns a string representation of the operator (including all sub-operators).
Class Method Details
.deserialize(serialized_op) ⇒ BaseOperator
Deserializes an operator from a string. String must be YAML-serialized.
36 37 38 |
# File 'lib/criteria_operator/base_operator.rb', line 36 def self.deserialize(serialized_op) YAML.safe_load(serialized_op, ObjectSpace.each_object(Class).select { |klass| klass < BaseOperator }) end |
.serialize(op) ⇒ String
Returns a string representation of an operator (including all sub-operators). YAML is used for serialization.
28 29 30 |
# File 'lib/criteria_operator/base_operator.rb', line 28 def self.serialize(op) YAML.dump(op) end |
Instance Method Details
#clone ⇒ BaseOperator
Clones an operator with all sub-operators, creating a deep copy.
13 14 15 |
# File 'lib/criteria_operator/base_operator.rb', line 13 def clone raise NotImplementedError end |
#serialize ⇒ String
Returns a string representation of the operator (including all sub-operators). YAML is used for serialization.
20 21 22 |
# File 'lib/criteria_operator/base_operator.rb', line 20 def serialize BaseOperator.serialize(self) end |