Class: Schema2type::SchemaConverter
- Inherits:
-
Object
- Object
- Schema2type::SchemaConverter
- Defined in:
- lib/schema2type/schema_converter.rb
Constant Summary collapse
- TYPE_STRING =
'string'.freeze
- TYPE_NUMBER =
'number'.freeze
- TYPE_BOOLEAN =
'boolean'.freeze
- TYPE_DATE =
'Date'.freeze
- COLUMN_METHODS =
YAML.load_file(File.(__dir__) + '/conversion_table.yml').to_a
Instance Attribute Summary collapse
-
#property_lines ⇒ Object
readonly
Returns the value of attribute property_lines.
-
#snake_case ⇒ Object
readonly
Returns the value of attribute snake_case.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(table_name:, snake_case: false) ⇒ SchemaConverter
constructor
A new instance of SchemaConverter.
- #method_missing ⇒ Object
- #result ⇒ Object
Constructor Details
#initialize(table_name:, snake_case: false) ⇒ SchemaConverter
Returns a new instance of SchemaConverter.
24 25 26 27 28 |
# File 'lib/schema2type/schema_converter.rb', line 24 def initialize(table_name:, snake_case: false) @property_lines = [] @table_name = table_name.singularize.camelize @snake_case = snake_case end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
34 35 36 |
# File 'lib/schema2type/schema_converter.rb', line 34 def method_missing(*) # To exclude unnecessary methods end |
Instance Attribute Details
#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 |
#snake_case ⇒ Object (readonly)
Returns the value of attribute snake_case.
6 7 8 |
# File 'lib/schema2type/schema_converter.rb', line 6 def snake_case @snake_case 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
14 15 16 17 18 19 20 |
# File 'lib/schema2type/schema_converter.rb', line 14 def self.define_convert_methods(methods) methods.each do |m| define_method(m[0]) do |name, *| push_property_line name: name, type: m[1], options: end end end |
Instance Method Details
#result ⇒ Object
30 31 32 |
# File 'lib/schema2type/schema_converter.rb', line 30 def result ["type #{table_name} = {", property_lines, "}\n"].flatten end |