Class: NoSE::Condition
Overview
A single condition in a where clause
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#is_range ⇒ Object
(also: #range?)
readonly
Returns the value of attribute is_range.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare conditions equal by their field and operator.
- #hash ⇒ Object
-
#initialize(field, operator, value) ⇒ Condition
constructor
A new instance of Condition.
- #inspect ⇒ Object
-
#resolve_foreign_key ⇒ Condition
If the condition is on a foreign key, resolve it to the primary key of the related entity.
Constructor Details
#initialize(field, operator, value) ⇒ Condition
Returns a new instance of Condition.
9 10 11 12 13 14 15 16 17 |
# File 'lib/nose/statements.rb', line 9 def initialize(field, operator, value) @field = field @operator = operator @is_range = [:>, :>=, :<, :<=].include? operator @value = value # XXX: Not frozen by now to support modification during query execution # freeze end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
6 7 8 |
# File 'lib/nose/statements.rb', line 6 def field @field end |
#is_range ⇒ Object (readonly) Also known as: range?
Returns the value of attribute is_range.
6 7 8 |
# File 'lib/nose/statements.rb', line 6 def is_range @is_range end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
6 7 8 |
# File 'lib/nose/statements.rb', line 6 def operator @operator end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/nose/statements.rb', line 6 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare conditions equal by their field and operator
25 26 27 |
# File 'lib/nose/statements.rb', line 25 def ==(other) @field == other.field && @operator == other.operator end |
#hash ⇒ Object
30 31 32 |
# File 'lib/nose/statements.rb', line 30 def hash Zlib.crc32 [@field.id, @operator].to_s end |
#inspect ⇒ Object
19 20 21 |
# File 'lib/nose/statements.rb', line 19 def inspect "#{@field.inspect} #{@operator} #{value}" end |
#resolve_foreign_key ⇒ Condition
If the condition is on a foreign key, resolve it to the primary key of the related entity
37 38 39 40 41 |
# File 'lib/nose/statements.rb', line 37 def resolve_foreign_key return self unless field.is_a?(Fields::ForeignKeyField) Condition.new @field.entity.id_field, @operator, @value end |