class Schema2type::SchemaConverter
Constants
- COLUMN_METHODS
- ID_PROPERTY_LINE_TEXT
Attributes
is_snake_case[R]
property_lines[R]
table_name[R]
Public Class Methods
define_convert_methods(methods)
click to toggle source
# File lib/schema2type/schema_converter.rb, line 11 def self.define_convert_methods(methods) methods.each do |m| define_method(m[0]) do |name, *options| convert_property_line_and_push name: name, type: m[1], options: options end end end
new(table_name:, is_snake_case: false)
click to toggle source
# File lib/schema2type/schema_converter.rb, line 21 def initialize(table_name:, is_snake_case: false) @property_lines = [] @table_name = table_name.singularize.camelize @is_snake_case = is_snake_case end
Public Instance Methods
converted_type_lines()
click to toggle source
# File lib/schema2type/schema_converter.rb, line 27 def converted_type_lines ["type #{table_name} = {", ID_PROPERTY_LINE_TEXT, property_lines, "}\n"].flatten end
method_missing(*)
click to toggle source
# File lib/schema2type/schema_converter.rb, line 31 def method_missing(*) # To exclude unnecessary methods # TODO: add error handling end
Private Instance Methods
convert_property_line_and_push(name:, type:, options:)
click to toggle source
# File lib/schema2type/schema_converter.rb, line 38 def convert_property_line_and_push(name:, type:, options:) is_non_nullable = options[0] && options[0].key?(:null) && !options[0][:null] formatted_name = is_snake_case ? name.underscore : name.camelcase(:lower) property_line = is_non_nullable ? "#{formatted_name}: #{type};" : "#{formatted_name}: #{type} | null;" property_lines << " #{property_line}" end