Class: RapidRunty::Model::Base
Class Method Summary
collapse
#destroy, included, #save
Class Method Details
.column_names ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/rapid_runty/model/base.rb', line 38
def self.column_names
columns = []
@property.each do |column_name, constraints|
properties_and_constraints = []
properties_and_constraints << column_name.to_s
constraints.each do |attribute, value|
properties_and_constraints << send(attribute.downcase.to_s, value)
end
columns << properties_and_constraints.join(' ')
end
columns
end
|
.create_table ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/rapid_runty/model/base.rb', line 18
def self.create_table
DB.execute_query(
"CREATE TABLE IF NOT EXISTS #{@table}" \
"(#{column_names.join(', ')})"
)
@property.keys.each(&method(:attr_accessor))
end
|
.nullable(is_null) ⇒ Object
30
31
32
|
# File 'lib/rapid_runty/model/base.rb', line 30
def self.nullable(is_null)
'NOT NULL' unless is_null
end
|
.primary_key(primary) ⇒ Object
26
27
28
|
# File 'lib/rapid_runty/model/base.rb', line 26
def self.primary_key(primary)
'PRIMARY KEY AUTOINCREMENT' if primary
end
|
.property(field, attr) ⇒ Object
13
14
15
16
|
# File 'lib/rapid_runty/model/base.rb', line 13
def self.property(field, attr)
@property ||= {}
@property[field] = attr
end
|
.to_table(name) ⇒ Object
9
10
11
|
# File 'lib/rapid_runty/model/base.rb', line 9
def self.to_table(name)
@table = name.to_s
end
|
.type(value) ⇒ Object
34
35
36
|
# File 'lib/rapid_runty/model/base.rb', line 34
def self.type(value)
value.to_s
end
|