schema2type 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/exe/schema2type +1 -1
- data/lib/schema2type/cli.rb +5 -34
- data/lib/schema2type/covert_service.rb +39 -0
- data/lib/schema2type/schema_converter.rb +1 -1
- data/lib/schema2type/version.rb +1 -1
- data/lib/schema2type.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d907bb961b8e4dd1d7c94732012dc0aafd75c4e29aef02027ef5b5c7751889f
|
4
|
+
data.tar.gz: 6494b9e501419c0f9a300ff5b2d056f9224296ddb262b4f709337dd53cabe765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b851eb75ea3a0a08bbb9a1e9d9f9c097d47b5d81b8d129afc396cd5f9cc27f7e1d8958a702e167457f9adf6c7b8044cd07d4c0a99f59422e5e7b7d3f4c1320
|
7
|
+
data.tar.gz: 8e4cec8d0f67e5835ff6dd7c28a457b364c27458f9ce1734a211961ffb28772b726183d990fcbc6682c56cddca568900a51361df75b859b5c2dcaf338ccfec95
|
data/Gemfile.lock
CHANGED
data/exe/schema2type
CHANGED
@@ -5,4 +5,4 @@ require 'schema2type'
|
|
5
5
|
|
6
6
|
params = ARGV.getopts('s:o:n:', 'snake')
|
7
7
|
|
8
|
-
Schema2type.execute(input_file: params[
|
8
|
+
Schema2type.execute(input_file: params['s'], out_file: params['o'], name_space: params['n'], snake_case: params['snake'])
|
data/lib/schema2type/cli.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
module Schema2type
|
2
2
|
|
3
|
-
DEFAULT_SCHEMA_PATH = "./db/schema.rb"
|
4
|
-
DEFAULT_NAME_SPACE = "schema"
|
3
|
+
DEFAULT_SCHEMA_PATH = "./db/schema.rb".freeze
|
4
|
+
DEFAULT_NAME_SPACE = "schema".freeze
|
5
5
|
|
6
6
|
def self.execute(input_file:, out_file:, name_space:, snake_case:)
|
7
|
-
@@converted_types = []
|
8
|
-
@@snake_case = snake_case
|
9
7
|
|
10
|
-
eval(File.read(input_file || DEFAULT_SCHEMA_PATH))
|
11
|
-
|
12
|
-
convert_type_text = @@converted_types.map { |t| " #{t}" }.join("\n").strip
|
8
|
+
result = eval(File.read(input_file || DEFAULT_SCHEMA_PATH), CovertService.new(snake_case).get_binding)
|
13
9
|
|
14
10
|
File.open(out_file, "w") do |f|
|
15
11
|
f.puts <<~EOS
|
@@ -17,38 +13,13 @@ module Schema2type
|
|
17
13
|
|
18
14
|
/**
|
19
15
|
* auto-generated file
|
20
|
-
* schema version: #{
|
16
|
+
* schema version: #{result[:version]}
|
21
17
|
* This file was automatically generated by schema2type
|
22
18
|
*/
|
23
19
|
declare namespace #{name_space || DEFAULT_NAME_SPACE} {
|
24
|
-
#{
|
20
|
+
#{result[:lines]}
|
25
21
|
}
|
26
22
|
EOS
|
27
23
|
end
|
28
24
|
end
|
29
|
-
|
30
|
-
def self.convert_schema(table_name, *)
|
31
|
-
converter = SchemaConverter.new(table_name: table_name, snake_case: @@snake_case)
|
32
|
-
|
33
|
-
yield converter
|
34
|
-
|
35
|
-
@@converted_types.concat converter.result
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.method_missing(*arg)
|
39
|
-
# To exclude unnecessary methods
|
40
|
-
end
|
41
|
-
|
42
|
-
module ActiveRecord
|
43
|
-
module Schema
|
44
|
-
def self.define(version)
|
45
|
-
$schema_version = version[:version]
|
46
|
-
yield
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class << self
|
52
|
-
alias :create_table :convert_schema
|
53
|
-
end
|
54
25
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Schema2type
|
2
|
+
class CovertService
|
3
|
+
def initialize(snake_case)
|
4
|
+
@converted_types = []
|
5
|
+
@snake_case = snake_case
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_binding
|
9
|
+
binding
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_table(table_name, *)
|
13
|
+
converter = SchemaConverter.new(table_name: table_name, snake_case: @snake_case)
|
14
|
+
yield converter
|
15
|
+
@converted_types.concat converter.result
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(*)
|
19
|
+
# To exclude unnecessary methods
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.method_missing(*)
|
23
|
+
# To exclude unnecessary methods
|
24
|
+
end
|
25
|
+
|
26
|
+
module ActiveRecord
|
27
|
+
module Schema
|
28
|
+
def self.define(*arg)
|
29
|
+
converted_types = yield
|
30
|
+
converted_type_lines = converted_types.map { |t| " #{t}" }.join("\n").strip
|
31
|
+
{
|
32
|
+
lines: converted_type_lines,
|
33
|
+
version: arg[0][:version]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -3,7 +3,7 @@ require 'active_support/inflector'
|
|
3
3
|
|
4
4
|
module Schema2type
|
5
5
|
class SchemaConverter
|
6
|
-
attr_reader :property_lines, :table_name, :
|
6
|
+
attr_reader :property_lines, :table_name, :snake_case
|
7
7
|
|
8
8
|
TYPE_STRING = 'string'.freeze
|
9
9
|
TYPE_NUMBER = 'number'.freeze
|
data/lib/schema2type/version.rb
CHANGED
data/lib/schema2type.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'schema2type/version'
|
2
2
|
require 'schema2type/schema_converter'
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'schema2type/covert_service'
|
4
|
+
require 'schema2type/cli'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema2type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/schema2type.rb
|
91
91
|
- lib/schema2type/cli.rb
|
92
92
|
- lib/schema2type/conversion_table.yml
|
93
|
+
- lib/schema2type/covert_service.rb
|
93
94
|
- lib/schema2type/schema_converter.rb
|
94
95
|
- lib/schema2type/version.rb
|
95
96
|
- schema2type.gemspec
|