Class: CriteriaOperator::BaseOperator Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/criteria_operator/base_operator.rb

Overview

This class is abstract.

Subclass and override #clone to implement.

Base class for all criteria operators. Provides operator overloads and other useful utility and convenience functions.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deserialize(serialized_op) ⇒ BaseOperator

Deserializes an operator from a string. String must be YAML-serialized.

Parameters:

  • serialized_op (String)

    The serialized operator.

Returns:



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.

Parameters:

Returns:

  • (String)

    The serialized operator.



28
29
30
# File 'lib/criteria_operator/base_operator.rb', line 28

def self.serialize(op)
  YAML.dump(op)
end

Instance Method Details

#cloneBaseOperator

This method is abstract.

Clones an operator with all sub-operators, creating a deep copy.

Returns:

Raises:



13
14
15
# File 'lib/criteria_operator/base_operator.rb', line 13

def clone
  raise NotImplementedError
end

#serializeString

Returns a string representation of the operator (including all sub-operators). YAML is used for serialization.

Returns:

  • (String)

    The serialized operator.



20
21
22
# File 'lib/criteria_operator/base_operator.rb', line 20

def serialize
  BaseOperator.serialize(self)
end