Class: Schema2type::SchemaConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/schema2type/schema_converter.rb

Constant Summary collapse

TYPE_STRING =
"string"
TYPE_NUMBER =
"number"
TYPE_BOOLEAN =
"string"
TYPE_DATE =
"Date"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name:) ⇒ SchemaConverter

Returns a new instance of SchemaConverter.



13
14
15
16
# File 'lib/schema2type/schema_converter.rb', line 13

def initialize(table_name:)
  @out_text = []
  @table_name = table_name
end

Instance Attribute Details

#out_textObject

Returns the value of attribute out_text.



5
6
7
# File 'lib/schema2type/schema_converter.rb', line 5

def out_text
  @out_text
end

#table_nameObject (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

Instance Method Details

#bigint(name, *options) ⇒ Object



35
36
37
# File 'lib/schema2type/schema_converter.rb', line 35

def bigint(name, *options)
  push_property_line name: name, type: TYPE_NUMBER, options: options
end

#binary(name, *options) ⇒ Object



55
56
57
# File 'lib/schema2type/schema_converter.rb', line 55

def binary(name, *options)
  push_property_line name: name, type: TYPE_STRING, options: options
end

#boolean(name, *options) ⇒ Object



43
44
45
# File 'lib/schema2type/schema_converter.rb', line 43

def boolean(name, *options)
  push_property_line name: name, type: TYPE_BOOLEAN, options: options
end

#date(name, *options) ⇒ Object



23
24
25
# File 'lib/schema2type/schema_converter.rb', line 23

def date(name, *options)
  push_property_line name: name, type: TYPE_STRING, options: options
end

#datetime(name, *options) ⇒ Object



59
60
61
# File 'lib/schema2type/schema_converter.rb', line 59

def datetime(name, *options)
  push_property_line name: name, type: TYPE_DATE, options: options
end

#decimal(name, *options) ⇒ Object



47
48
49
# File 'lib/schema2type/schema_converter.rb', line 47

def decimal(name, *options)
  push_property_line name: name, type: TYPE_NUMBER, options: options
end

#finalizeObject



18
19
20
21
# File 'lib/schema2type/schema_converter.rb', line 18

def finalize
  @out_text.unshift "type #{@table_name.singularize.camelize} = {"
  @out_text << "}\n"
end

#index(*arg) ⇒ Object



67
68
# File 'lib/schema2type/schema_converter.rb', line 67

def index(*arg)
end

#integer(name, *options) ⇒ Object



31
32
33
# File 'lib/schema2type/schema_converter.rb', line 31

def integer(name, *options)
  push_property_line name: name, type: TYPE_NUMBER, options: options
end

#json(name, *options) ⇒ Object



51
52
53
# File 'lib/schema2type/schema_converter.rb', line 51

def json(name, *options)
  push_property_line name: name, type: TYPE_STRING, options: options
end

#string(name, *options) ⇒ Object



27
28
29
# File 'lib/schema2type/schema_converter.rb', line 27

def string(name, *options)
  push_property_line name: name, type: TYPE_STRING, options: options
end

#text(name, *options) ⇒ Object



39
40
41
# File 'lib/schema2type/schema_converter.rb', line 39

def text(name, *options)
  push_property_line name: name, type: TYPE_STRING, options: options
end

#timestamp(name, *options) ⇒ Object



63
64
65
# File 'lib/schema2type/schema_converter.rb', line 63

def timestamp(name, *options)
  push_property_line name: name, type: TYPE_DATE, options: options
end