Class: Dynamicloud::API::Criteria::ExistsCondition

Inherits:
Condition
  • Object
show all
Defined in:
lib/dynamic_criteria.rb

Overview

End of BetweenCondition class

Constant Summary

Constants inherited from Condition

Condition::ROOT, Condition::WITHOUT

Instance Method Summary collapse

Constructor Details

#initialize(model_id, aliass, not_exists) ⇒ ExistsCondition

Builds an instance with a specific model an alias

Parameters:

  • model_id

    Model ID

  • aliass

    alias to this model



163
164
165
166
167
168
169
# File 'lib/dynamic_criteria.rb', line 163

def initialize(model_id, aliass, not_exists)
  @model_id = model_id
  @aliass = aliass
  @not_exists = not_exists
  @conditions = []
  @joins = []
end

Instance Method Details

#add(condition) ⇒ Object

This method will add a new condition to this ExistsCondition.

*

Parameters:

  • condition

    new condition to a list of conditions to use

Returns:

  • this instance of ExistsCondition



175
176
177
178
# File 'lib/dynamic_criteria.rb', line 175

def add(condition)
  @conditions.push(condition)
  self
end

#join(join) ⇒ Object

Add a join to the list of joins

Parameters:

  • join

    join clause

Returns:

  • this instance of ExistsCondition



184
185
186
187
# File 'lib/dynamic_criteria.rb', line 184

def join(join)
  @joins.push(join)
  self
end

#set_alias(aliass) ⇒ Object

Sets the related alias to the model

Parameters:

  • aliass

    related alias to the model



192
193
194
# File 'lib/dynamic_criteria.rb', line 192

def set_alias(aliass)
  @alias = aliass
end

#set_model(model_id) ⇒ Object

Sets the related model to this exists condition. With this model, you can

Parameters:

  • model_id

    related model



200
201
202
# File 'lib/dynamic_criteria.rb', line 200

def set_model(model_id)
  @model_id = model_id
end

#to_record_string(parent) ⇒ Object

This method will return a String of this condition

Parameters:

  • parent

    this is the parent of this condition

Returns:

  • a json



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/dynamic_criteria.rb', line 208

def to_record_string(parent)
  built = (@not_exists ? "\"$nexists\"" : "\"$exists\"") + ': { ' + Dynamicloud::API::DynamicloudHelper.build_join_tag(@joins) + ', ' + (@model_id.nil? ? '' : ("\"model\": " + @model_id.to_s + ', ')) + (@aliass.nil? ? '' : ("\"alias\": \"" + @aliass + "\", ")) + "\"where\": {"

  if @conditions.length > 0
    global = @conditions[0]
    if @conditions.length > 1
      @conditions = @conditions[1..@conditions.length]
      @conditions.each do |condition|
        global = Dynamicloud::API::Criteria::ANDCondition.new global, condition
      end
    end

    built = built + global.to_record_string(Dynamicloud::API::Criteria::Condition::ROOT)
  end

  built + '}}'
end