Class: Perpetuity::Postgres::QueryAttribute
- Inherits:
-
Object
- Object
- Perpetuity::Postgres::QueryAttribute
- Defined in:
- lib/perpetuity/postgres/query_attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #any? ⇒ Boolean
- #count ⇒ Object
- #id ⇒ Object
- #in(collection) ⇒ Object
-
#initialize(name) ⇒ QueryAttribute
constructor
A new instance of QueryAttribute.
- #nil? ⇒ Boolean
- #none? ⇒ Boolean
- #to_db ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ QueryAttribute
Returns a new instance of QueryAttribute.
9 10 11 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 9 def initialize name @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 7 def name @name end |
Instance Method Details
#any? ⇒ Boolean
33 34 35 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 33 def any? QueryExpression.new count, :>, 0 end |
#count ⇒ Object
29 30 31 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 29 def count SQLFunction.new('json_array_length', self) end |
#id ⇒ Object
41 42 43 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 41 def id QueryAttribute.new "#{name}->'__metadata__'->>'id'" end |
#in(collection) ⇒ Object
21 22 23 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 21 def in collection QueryExpression.new self, :in, collection end |
#nil? ⇒ Boolean
25 26 27 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 25 def nil? QueryExpression.new self, :==, nil end |
#none? ⇒ Boolean
37 38 39 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 37 def none? QueryExpression.new count, :==, 0 end |
#to_db ⇒ Object
49 50 51 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 49 def to_db (self != nil).to_db end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/perpetuity/postgres/query_attribute.rb', line 45 def to_s name.to_s end |