Class: Peictt::ConstraintsParser
- Defined in:
- lib/peictt/orm/constraints_parser.rb
Constant Summary collapse
- UNIQUE =
"UNIQUE".freeze
- NULL =
"NULL".freeze
- NOT_NULL =
"NOT NULL".freeze
- PRIMARY_KEY =
"PRIMARY KEY".freeze
- DEFAULT =
"".freeze
- AUTO_INCREMENT =
"AUTOINCREMENT".freeze
Class Method Summary collapse
- .auto_increment(value = false) ⇒ Object
- .default(value = "") ⇒ Object
- .null(value = false) ⇒ Object
- .parse(constraints = {}) ⇒ Object
- .primary_key(value = false) ⇒ Object
- .unique(value = false) ⇒ Object
Class Method Details
.auto_increment(value = false) ⇒ Object
28 29 30 |
# File 'lib/peictt/orm/constraints_parser.rb', line 28 def self.auto_increment(value = false) @result << AUTO_INCREMENT if value end |
.default(value = "") ⇒ Object
37 38 39 |
# File 'lib/peictt/orm/constraints_parser.rb', line 37 def self.default(value = "") @result << "DEFAULT '#{value}'" end |
.null(value = false) ⇒ Object
32 33 34 35 |
# File 'lib/peictt/orm/constraints_parser.rb', line 32 def self.null(value = false) @result << NULL if value @result << NOT_NULL unless value end |
.parse(constraints = {}) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/peictt/orm/constraints_parser.rb', line 11 def self.parse(constraints = {}) constraints.each do |key, value| send(key, value) end result = @result.dup @result.clear result end |
.primary_key(value = false) ⇒ Object
20 21 22 |
# File 'lib/peictt/orm/constraints_parser.rb', line 20 def self.primary_key(value = false) @result << PRIMARY_KEY if value end |