Class: MetaDb::CheckConstraint
- Inherits:
-
Constraint
- Object
- DbObject
- Constraint
- MetaDb::CheckConstraint
- Defined in:
- lib/meta_db/db_object.rb
Overview
Note that #columns is always empty for check constraints
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
SQL check expression.
Attributes inherited from Constraint
Attributes inherited from DbObject
Instance Method Summary collapse
-
#initialize(table, name, expression) ⇒ CheckConstraint
constructor
A new instance of CheckConstraint.
-
#ruby_expression ⇒ Object
Half-baked SQL-to-ruby expression transpiler.
Methods inherited from Constraint
Methods inherited from DbObject
#<=>, #[], attrs, #dot, #dump, #dump_attrs, init, #inspect, #path
Constructor Details
#initialize(table, name, expression) ⇒ CheckConstraint
Returns a new instance of CheckConstraint.
306 307 308 309 |
# File 'lib/meta_db/db_object.rb', line 306 def initialize(table, name, expression) super(table, name, []) @expression = expression end |
Instance Attribute Details
#expression ⇒ Object (readonly)
SQL check expression
299 300 301 |
# File 'lib/meta_db/db_object.rb', line 299 def expression @expression end |
Instance Method Details
#ruby_expression ⇒ Object
Half-baked SQL-to-ruby expression transpiler
302 303 304 |
# File 'lib/meta_db/db_object.rb', line 302 def ruby_expression # Very simple @ruby ||= sql.sub(/\((.*)\)/, "\\1").gsub(/\((\w+) IS NOT NULL\)/, "!\\1.nil?").gsub(/ OR /, " || ") end |