misete 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +26 -0
- data/README.md +29 -0
- data/Rakefile +32 -0
- data/bin/console +48 -0
- data/bin/misete +52 -0
- data/bin/setup +29 -0
- data/lib/misete.rb +35 -0
- data/lib/misete/schema_parser.rb +120 -0
- data/lib/misete/schema_printer.rb +51 -0
- data/lib/misete/version.rb +25 -0
- data/misete.gemspec +51 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d885170386be6d8c0bbcfbcb83eb5090615d25019932bd101c8a1a47c965c4e9
|
4
|
+
data.tar.gz: cd758b9c5ad4dd8e640ded2dad4a2b45cda073b5209a4e15acab39204abc6906
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60a81f5118225f49e5800081e064f65864d068ca1e8d619c0d9a1ff3c1fce1985152a467a2f579871de8778277093cd9b3da0c486b5e60e34ae2982a68956ee2
|
7
|
+
data.tar.gz: 91e8dd6ceae231eb2a70b8f87fb863a83ef7d17828446f7376bf61a4a1faf6b528fecb613ee02f0e98d2df5f6fc6f111e6eaaf5968a6b17ab4cc412aad29787f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
source "https://rubygems.org"
|
22
|
+
|
23
|
+
# Specify your gem's dependencies in misete.gemspec
|
24
|
+
gemspec
|
25
|
+
|
26
|
+
gem "rake", "~> 12.0"
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Misete
|
2
|
+
|
3
|
+
It is a command line tool to to show your schema.rb in Ruby on Rails projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'misete'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install misete
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Run in you Rails project directory:
|
24
|
+
|
25
|
+
$ misete schema
|
26
|
+
|
27
|
+
To display help and show more oprions run:
|
28
|
+
|
29
|
+
$ misete schema -h
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require "bundler/gem_tasks"
|
22
|
+
task :default => :spec
|
23
|
+
|
24
|
+
require "rake/testtask"
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << "test"
|
28
|
+
t.libs << "lib"
|
29
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
30
|
+
end
|
31
|
+
|
32
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'bundler/setup'
|
25
|
+
require 'misete'
|
26
|
+
|
27
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
28
|
+
# with your gem easier. You can also use a different console, if you like.
|
29
|
+
|
30
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
31
|
+
# require "pry"
|
32
|
+
# Pry.start
|
33
|
+
|
34
|
+
require 'irb'
|
35
|
+
|
36
|
+
ROOT_DIR = File.expand_path('..', __dir__)
|
37
|
+
RELOAD_DIRS = ['lib'].freeze
|
38
|
+
|
39
|
+
def reload!
|
40
|
+
puts 'Reloading ...'
|
41
|
+
|
42
|
+
RELOAD_DIRS.each do |dir|
|
43
|
+
Dir.glob("#{ROOT_DIR}/#{dir}/**/*.rb").each { |file| load(file) }
|
44
|
+
end
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
IRB.start(__FILE__)
|
data/bin/misete
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
STDOUT.sync = true
|
25
|
+
|
26
|
+
require 'misete'
|
27
|
+
require 'slop'
|
28
|
+
require 'misete/version'
|
29
|
+
|
30
|
+
return puts "try 'misete schema'" if ARGV[0] != 'schema'
|
31
|
+
|
32
|
+
opts = Slop.parse(ARGV[1..-1], strict: true, help: true) do |o|
|
33
|
+
o.bool '-h', '--help', 'Show help'
|
34
|
+
o.string(
|
35
|
+
'-i',
|
36
|
+
'--input',
|
37
|
+
'Input file schema.rb',
|
38
|
+
)
|
39
|
+
o.array(
|
40
|
+
'-t',
|
41
|
+
'--tables',
|
42
|
+
'Table list to shown',
|
43
|
+
delimiter: ' '
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
if opts.help?
|
48
|
+
puts opts
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
Misete.schema(opts.to_h)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
set -euo pipefail
|
24
|
+
IFS=$'\n\t'
|
25
|
+
set -vx
|
26
|
+
|
27
|
+
bundle install
|
28
|
+
|
29
|
+
# Do any other automated setup that you need to do here
|
data/lib/misete.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'misete/version'
|
24
|
+
require 'misete/schema_parser'
|
25
|
+
require 'misete/schema_printer'
|
26
|
+
require 'misete/version'
|
27
|
+
|
28
|
+
module Misete
|
29
|
+
def self.schema(options = {})
|
30
|
+
schema_path = options.delete(:input) || File.join(Dir.pwd, 'db/schema.rb')
|
31
|
+
options.delete(:tables) if options[:tables].empty?
|
32
|
+
parsed_schema = Misete::SchemaParser.parse(schema_path, options)
|
33
|
+
Misete::SchemaPrinter.show(parsed_schema)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
class Misete::SchemaParser
|
24
|
+
def initialize(schema_path, params = {})
|
25
|
+
@schema = init_hash
|
26
|
+
@current_table = nil
|
27
|
+
pp params
|
28
|
+
@table_names = params[:tables]
|
29
|
+
@schema_path = schema_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse
|
33
|
+
file.each_line { |line| process_line(line) }
|
34
|
+
@schema
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.parse(filename, params={})
|
38
|
+
new(filename, params).parse
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def file
|
44
|
+
File.open(@schema_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def process_line(line)
|
48
|
+
if table?
|
49
|
+
process_columns(line)
|
50
|
+
else
|
51
|
+
process_table_name(line)
|
52
|
+
process_table_options(line) if table?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def process_columns(line)
|
57
|
+
add_column(extract_column(line))
|
58
|
+
end_table if line.strip == 'end'
|
59
|
+
end
|
60
|
+
|
61
|
+
def extract_column(line)
|
62
|
+
column, options = line.split(',', 2)
|
63
|
+
column_type, column_name = column.match(/t.(?<type>\w+) "(?<name>\S+)"/).to_a.last(2)
|
64
|
+
|
65
|
+
return {} unless column_name
|
66
|
+
|
67
|
+
{}.tap do |hash|
|
68
|
+
hash[column_name] = { type: column_type.strip }
|
69
|
+
hash[column_name].merge!({ params: options.strip }) if options
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_column(column)
|
74
|
+
@schema[:tables][@current_table][:columns] ||= {}
|
75
|
+
@schema[:tables][@current_table][:columns].merge!(column)
|
76
|
+
end
|
77
|
+
|
78
|
+
def process_table_name(line)
|
79
|
+
table_name = extract_table_name(line)
|
80
|
+
return if @table_names && !@table_names.include?(table_name)
|
81
|
+
|
82
|
+
begin_table(table_name) if table_name
|
83
|
+
end
|
84
|
+
|
85
|
+
def extract_table_name(line)
|
86
|
+
matches = line.match(/create_table "(?<table_name>\S+)",/)
|
87
|
+
matches[:table_name].strip if matches
|
88
|
+
end
|
89
|
+
|
90
|
+
def process_table_options(line)
|
91
|
+
params = extract_options(line)
|
92
|
+
@schema[:tables][@current_table].merge!(params: params) if params
|
93
|
+
end
|
94
|
+
|
95
|
+
def extract_options(line)
|
96
|
+
matches = line.match(/create_table "(?<table_name>\S+)", (?<options>.*:.*?) .(?:(?!do).)/)
|
97
|
+
|
98
|
+
return unless matches && matches[:options]
|
99
|
+
|
100
|
+
pairs = matches[:options].gsub(':', '').split(',').map { |pairs| pairs.split(' ', 2) }
|
101
|
+
Hash[pairs]
|
102
|
+
end
|
103
|
+
|
104
|
+
def begin_table(table_name)
|
105
|
+
@current_table = table_name
|
106
|
+
@schema[:tables][table_name] = {}
|
107
|
+
end
|
108
|
+
|
109
|
+
def end_table
|
110
|
+
@current_table = nil
|
111
|
+
end
|
112
|
+
|
113
|
+
def table?
|
114
|
+
@current_table
|
115
|
+
end
|
116
|
+
|
117
|
+
def init_hash
|
118
|
+
Hash.new { |k,v| k[v] = {} }
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
class Misete::SchemaPrinter
|
24
|
+
def self.show(parsed_schema)
|
25
|
+
max_indent = calc_indent(parsed_schema)
|
26
|
+
parsed_schema[:tables].each do |name, data|
|
27
|
+
print_table_header(name)
|
28
|
+
data[:columns].each do |name, data|
|
29
|
+
print_column(name, data, max_indent)
|
30
|
+
end
|
31
|
+
print "#\n"
|
32
|
+
print "\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def self.calc_indent(parsed_schema)
|
39
|
+
parsed_schema[:tables].map { |_, data| data.dig(:columns)&.keys }.flatten.map(&:size).max
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.print_table_header(name)
|
43
|
+
print "\n"
|
44
|
+
print "# Table name: #{name}\n"
|
45
|
+
print "#\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.print_column(name, data, indent)
|
49
|
+
print "# #{name.ljust(indent)} :#{data[:type]}, #{data[:params]}\n"
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
module Misete
|
24
|
+
VERSION = "0.1.0"
|
25
|
+
end
|
data/misete.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2020 Konstantin Ermolchev
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
lib = File.expand_path('../lib', __FILE__)
|
22
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
23
|
+
|
24
|
+
require 'misete/version'
|
25
|
+
|
26
|
+
Gem::Specification.new do |spec|
|
27
|
+
spec.name = "misete"
|
28
|
+
spec.version = Misete::VERSION
|
29
|
+
spec.authors = ["Konstantin Ermolchev"]
|
30
|
+
spec.email = ["asqd117@gmail.com"]
|
31
|
+
|
32
|
+
spec.summary = %q{Shor summary coming soon}
|
33
|
+
spec.homepage = "https://github.com/asqd/misete"
|
34
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
35
|
+
|
36
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
37
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
38
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
39
|
+
|
40
|
+
# Specify which files should be added to the gem when it is released.
|
41
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
42
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
43
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
44
|
+
end
|
45
|
+
spec.bindir = "bin"
|
46
|
+
spec.executables = ['misete']
|
47
|
+
spec.require_paths = ["lib"]
|
48
|
+
spec.add_runtime_dependency 'slop'
|
49
|
+
spec.add_development_dependency 'minitest', '5.11.3'
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: misete
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Konstantin Ermolchev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.11.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.11.3
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- asqd117@gmail.com
|
44
|
+
executables:
|
45
|
+
- misete
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/misete
|
55
|
+
- bin/setup
|
56
|
+
- lib/misete.rb
|
57
|
+
- lib/misete/schema_parser.rb
|
58
|
+
- lib/misete/schema_printer.rb
|
59
|
+
- lib/misete/version.rb
|
60
|
+
- misete.gemspec
|
61
|
+
homepage: https://github.com/asqd/misete
|
62
|
+
licenses: []
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/asqd/misete
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.3.0
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.0.6
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Shor summary coming soon
|
84
|
+
test_files: []
|