Class: Momomoto::Datatype::Text
- Defined in:
- lib/momomoto/datatype/text.rb
Overview
Represents the data type Text.
Direct Known Subclasses
Class Method Summary collapse
-
.operator_sign(op) ⇒ Object
Additional operators for instances of Text.
Instance Method Summary collapse
-
#equal(a, b) ⇒ Object
Compares two values and returns true if equal or false otherwise.
-
#escape(input) ⇒ Object
Escapes
input
to be saved in database.
Methods inherited from Base
#compile_rule, #default, #default_operator, #filter_set, #initialize, #not_null?
Constructor Details
This class inherits a constructor from Momomoto::Datatype::Base
Class Method Details
.operator_sign(op) ⇒ Object
Additional operators for instances of Text. See Base#operator_sign
# Selects all posts having "surveillance" in their content field
# while ignoring case.
Posts.select( :content => {:ilike => 'surveillance'} )
31 32 33 34 35 36 37 38 |
# File 'lib/momomoto/datatype/text.rb', line 31 def self.operator_sign( op ) case op when :like then 'LIKE' when :ilike then 'ILIKE' else super( op ) end end |
Instance Method Details
#equal(a, b) ⇒ Object
Compares two values and returns true if equal or false otherwise. It is used to check if a row field has been changed so that only changed fields are written to database.
10 11 12 |
# File 'lib/momomoto/datatype/text.rb', line 10 def equal( a, b ) a.to_s == b.to_s end |
#escape(input) ⇒ Object
Escapes input
to be saved in database. Returns ‘NULL’ if input
is nil or empty. Otherwise escapes using Database#quote
17 18 19 20 21 22 23 |
# File 'lib/momomoto/datatype/text.rb', line 17 def escape( input ) if input.nil? || input.to_s.empty? "NULL" else Database.quote_string( input.to_s ) end end |