Module: Formatters::FieldsFormatter
Constant Summary
collapse
[
{ from: "'", to: "\\\\'" },
{ from: '\"', to: '"' }
].freeze
- TYPE_MAPPER =
{
string: 'varchar',
integer: 'int',
boolean: 'bool',
datetime: 'timestamp'
}.freeze
DefaultFieldFormatterHelper::DEFAULT_ARRAY_REGEX, DefaultFieldFormatterHelper::DEFAULT_BOOLEAN_REGEX, DefaultFieldFormatterHelper::DEFAULT_HASH_REGEX, DefaultFieldFormatterHelper::DEFAULT_LAMBDA_REGEX, DefaultFieldFormatterHelper::DEFAULT_NUMBER_REGEX, DefaultFieldFormatterHelper::DEFAULT_PATTERNS, DefaultFieldFormatterHelper::DEFAULT_STRING_REGEX
Instance Method Summary
collapse
Instance Method Details
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/schema_to_dbml/formatters/fields_formatter.rb', line 47
def (comment:)
return '' if .to_s.empty?
note = .dup
COMMENT_MAPPER.each do |mapper|
note.gsub!(mapper[:from], mapper[:to])
end
note = "#{note} " if note[-1, 1] == "'"
"note: '''#{note}'''"
end
|
31
32
33
34
35
36
37
38
39
|
# File 'lib/schema_to_dbml/formatters/fields_formatter.rb', line 31
def format_default(default:)
return '' if default.to_s.empty?
DEFAULT_PATTERNS.each do |pattern, replacement|
default = default.gsub(pattern, replacement)
end
default
end
|
41
42
43
44
45
|
# File 'lib/schema_to_dbml/formatters/fields_formatter.rb', line 41
def format_null(null:)
return '' if null.to_s.empty?
'not null'
end
|
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/schema_to_dbml/formatters/fields_formatter.rb', line 20
def format_type(type:, array:, limit:)
return '' if type.to_s.empty?
parsed = TYPE_MAPPER[type.to_sym] || type.to_s
return "#{parsed}[]" if array == 'true'
return "#{parsed}(#{limit})" if limit
parsed
end
|