Class: Linkage::Functions::Cast
Constant Summary
Constants inherited
from Data
Data::TYPE_CONVERSION_TREE
Instance Attribute Summary
#args
Attributes inherited from Data
#dataset, #name
Class Method Summary
collapse
Instance Method Summary
collapse
#==, [], #collation, #dataset, #dataset=, #initialize, #name, register, #static?
Methods inherited from Data
#collation, #database_type, #initialize, #merge, #static?
Class Method Details
.function_name ⇒ Object
4
5
6
|
# File 'lib/linkage/functions/cast.rb', line 4
def self.function_name
"cast"
end
|
.parameters ⇒ Object
8
9
10
|
# File 'lib/linkage/functions/cast.rb', line 8
def self.parameters
[[:any], [String]]
end
|
Instance Method Details
#ruby_type ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/linkage/functions/cast.rb', line 12
def ruby_type
type =
case @values[1]
when 'integer'
Fixnum
when 'binary'
File
else
raise "unknown type: #{@values[1]}"
end
{:type => type}
end
|
#to_expr(options = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/linkage/functions/cast.rb', line 26
def to_expr(options = {})
cast =
case @values[1]
when 'integer'
case dataset.database_type
when :sqlite, :postgres, :h2
:integer
when :mysql
:signed
end
when 'binary'
case dataset.database_type
when :sqlite
:blob
when :postgres
:bytea
when :mysql, :h2
:binary
end
end
if cast
@values[0].cast(cast)
end
end
|