Class: Dynamicloud::API::Criteria::ExistsCondition
- 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
-
#add(condition) ⇒ Object
This method will add a new condition to this ExistsCondition.
-
#initialize(model_id, aliass, not_exists) ⇒ ExistsCondition
constructor
Builds an instance with a specific model an alias.
-
#join(join) ⇒ Object
Add a join to the list of joins.
-
#set_alias(aliass) ⇒ Object
Sets the related alias to the model.
-
#set_model(model_id) ⇒ Object
Sets the related model to this exists condition.
-
#to_record_string(parent) ⇒ Object
This method will return a String of this condition.
Constructor Details
#initialize(model_id, aliass, not_exists) ⇒ ExistsCondition
Builds an instance with a specific model an alias
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.
*
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
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
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
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
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 |