Class: ParamsReady::Query::VariableOperatorPredicateDefinition

Inherits:
AbstractPredicateDefinition show all
Includes:
HavingAttribute
Defined in:
lib/params_ready/query/variable_operator_predicate.rb

Instance Attribute Summary collapse

Attributes inherited from Parameter::AbstractDefinition

#altn, #name

Instance Method Summary collapse

Methods inherited from Parameter::AbstractDefinition

#create, #from_hash, #from_input, #normalize_alternative_name, #parameter_class

Methods included from Extensions::Freezer

#freeze_variable, #freeze_variables, #variables_to_freeze

Methods included from Extensions::Finalizer

#obligatory, #obligatory!

Methods included from Extensions::ClassReaderWriter

#class_reader_writer

Methods included from Extensions::LateInit

#late_init

Methods included from Extensions::Collection

#collection

Methods included from Extensions::Freezer::InstanceMethods

#freeze

Constructor Details

#initialize(*args, attribute_name: nil, **opts) ⇒ VariableOperatorPredicateDefinition

Returns a new instance of VariableOperatorPredicateDefinition.



88
89
90
91
92
93
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 88

def initialize(*args, attribute_name: nil, **opts)
  super *args, **opts
  @attribute_name = attribute_name
  @struct_parameter_builder = Builder.builder(:struct).instance(name, altn: altn)
  @operator_parameter_builder = Builder.builder(:predicate_operator).instance(:operator, altn: :op)
end

Instance Attribute Details

#struct_parameterObject (readonly)

Returns the value of attribute struct_parameter.



86
87
88
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 86

def struct_parameter
  @struct_parameter
end

#struct_parameter_builderObject (readonly)

Returns the value of attribute struct_parameter_builder.



85
86
87
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 85

def struct_parameter_builder
  @struct_parameter_builder
end

Instance Method Details

#finishObject



113
114
115
116
117
118
119
120
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 113

def finish
  @struct_parameter = @struct_parameter_builder.build
  @struct_parameter_builder = nil
  @operator_parameter_builder = nil
  @type = nil

  super
end

#set_operators(array, &block) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 100

def set_operators(array, &block)
  context = Format.instance(:backend)

  operators = array.map do |name|
    PredicateRegistry.operator(name, context)
  end
  @operator_parameter_builder.include do
    constrain :enum, operators
  end
  @operator_parameter_builder.include(&block) unless block.nil?
  @struct_parameter_builder.add @operator_parameter_builder.build
end

#set_type(type) ⇒ Object



95
96
97
98
# File 'lib/params_ready/query/variable_operator_predicate.rb', line 95

def set_type(type)
  @type = type
  @struct_parameter_builder.add @type.finish
end