Class: Crudboy::Column
Constant Summary
collapse
- JAVA_TYPES =
{
"varchar" => 'String',
"char" => 'String',
"int" => 'Integer',
"bigint" => 'Long',
"tinyint" => 'Byte',
"date" => 'LocalDate',
"datetime" => 'LocalDateTime',
"timestamp" => 'LocalDateTime',
"decimal" => 'BigDecimal'
}
- JDBC_TYPES =
{
"varchar" => 'VARCHAR',
"char" => 'CHAR',
"int" => 'INTEGER',
"bigint" => 'BIGINT',
"tinyint" => 'TINYINT',
"date" => 'TIMESTAMP',
"datetime" => 'TIMESTAMP',
"timestamp" => 'TIMESTAMP',
"decimal" => 'DECIMAL'
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(column, primary) ⇒ Column
Returns a new instance of Column.
30
31
32
33
|
# File 'lib/crudboy/column.rb', line 30
def initialize(column, primary)
@active_record_column = column
@primary = primary
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **options, &block) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/crudboy/column.rb', line 78
def method_missing(method, *args, **options, &block)
if active_record_column.respond_to?(method)
active_record_column.send(method, *args, **options, &block)
else
super
end
end
|
Instance Attribute Details
#active_record_column ⇒ Object
Returns the value of attribute active_record_column.
28
29
30
|
# File 'lib/crudboy/column.rb', line 28
def active_record_column
@active_record_column
end
|
Returns the value of attribute primary.
28
29
30
|
# File 'lib/crudboy/column.rb', line 28
def primary
@primary
end
|
Instance Method Details
35
36
37
38
39
40
41
|
# File 'lib/crudboy/column.rb', line 35
def java_doc
<<-EOF.lstrip.chomp
/**
* #{}
*/
EOF
end
|
#java_type ⇒ Object
67
68
69
70
71
|
# File 'lib/crudboy/column.rb', line 67
def java_type
return 'Boolean' if sql_type == 'tinyint(1)'
raw_type = sql_type.scan(/^\w+/).first
JAVA_TYPES[raw_type]
end
|
#jdbc_type ⇒ Object
73
74
75
76
|
# File 'lib/crudboy/column.rb', line 73
def jdbc_type
raw_type = sql_type.scan(/^\w+/).first
JDBC_TYPES[raw_type]
end
|
#lower_camel_name ⇒ Object
59
60
61
|
# File 'lib/crudboy/column.rb', line 59
def lower_camel_name
name.camelcase(:lower)
end
|
#mybatis_equation ⇒ Object
47
48
49
|
# File 'lib/crudboy/column.rb', line 47
def mybatis_equation
format('`%s` = %s', name, mybatis_value_expression)
end
|
#mybatis_result_map ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/crudboy/column.rb', line 51
def mybatis_result_map
if @primary
format('<id column="%s" jdbcType="%s" property="%s" />', name, jdbc_type, lower_camel_name)
else
format('<result column="%s" jdbcType="%s" property="%s" />', name, jdbc_type, lower_camel_name)
end
end
|
#mybatis_value_expression ⇒ Object
43
44
45
|
# File 'lib/crudboy/column.rb', line 43
def mybatis_value_expression
format('#{%s,jdbcType=%s}', lower_camel_name, jdbc_type)
end
|
#upper_camel_name ⇒ Object
63
64
65
|
# File 'lib/crudboy/column.rb', line 63
def upper_camel_name
name.camelcase(:upper)
end
|