Class: Schema2type::SchemaConverter
- Inherits:
-
Object
- Object
- Schema2type::SchemaConverter
- Defined in:
- lib/schema2type/schema_converter.rb
Constant Summary collapse
- COLUMN_METHODS =
YAML.load_file(File.(__dir__) + '/conversion_table.yml').to_a
- ID_PROPERTY_LINE_TEXT =
" id: number;".freeze
Instance Attribute Summary collapse
-
#is_snake_case ⇒ Object
readonly
Returns the value of attribute is_snake_case.
-
#property_lines ⇒ Object
readonly
Returns the value of attribute property_lines.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
Instance Method Summary collapse
- #converted_type_lines ⇒ Object
-
#initialize(table_name:, is_snake_case: false) ⇒ SchemaConverter
constructor
A new instance of SchemaConverter.
- #method_missing ⇒ Object
Constructor Details
#initialize(table_name:, is_snake_case: false) ⇒ SchemaConverter
21 22 23 24 25 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
31 32 33 34 |
# File 'lib/schema2type/schema_converter.rb', line 31 def method_missing(*) # To exclude unnecessary methods # TODO: add error handling end |
Instance Attribute Details
#is_snake_case ⇒ Object (readonly)
Returns the value of attribute is_snake_case.
6 7 8 |
# File 'lib/schema2type/schema_converter.rb', line 6 def is_snake_case @is_snake_case end |
#property_lines ⇒ Object (readonly)
Returns the value of attribute property_lines.
6 7 8 |
# File 'lib/schema2type/schema_converter.rb', line 6 def property_lines @property_lines end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/schema2type/schema_converter.rb', line 6 def table_name @table_name end |
Class Method Details
.define_convert_methods(methods) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/schema2type/schema_converter.rb', line 11 def self.define_convert_methods(methods) methods.each do |m| define_method(m[0]) do |name, *| convert_property_line_and_push name: name, type: m[1], options: end end end |
Instance Method Details
#converted_type_lines ⇒ Object
27 28 29 |
# File 'lib/schema2type/schema_converter.rb', line 27 def converted_type_lines ["type #{table_name} = {", ID_PROPERTY_LINE_TEXT, property_lines, "}\n"].flatten end |