ratbug 0.0.1 → 0.0.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/lib/ratbug/generate_config.rb +10 -8
- data/lib/ratbug/generators/jbuilder_generator.rb +10 -2
- data/lib/ratbug/generators/typescript_generator.rb +10 -2
- data/lib/ratbug/table.rb +1 -6
- data/lib/ratbug/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79527c57486065571d60fa01210d87af021ac78888f8ea28faef6eb84ab1ad49
|
4
|
+
data.tar.gz: aa8e3c50dcb21b66b5d87117516984cf79a665a25ef335c83aca4196c121c118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 555c1c504c7ea332a1e05b674431761fcdb691f58b318128a7433159ea84b0880d09389e666f503629612611d25fe3303a6e88a8b48e6b92146ff36fcc683bd2
|
7
|
+
data.tar.gz: 50a95300d9dead24e0f13d926ca794f040b9d9afbeae977baaefb137caf763474929eaa9742a1b704d6b66675ab22dde27a24d949a347fb794b86b6340de9c17
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Ratbug
|
2
2
|
class GenerateConfig
|
3
3
|
VALID_OPTION_KEYS = %i[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
enabled_outputs
|
5
|
+
ts_prefer_type
|
6
|
+
ts_enum_output_type
|
7
|
+
ts_prefer_undefined
|
8
|
+
use_only_schema
|
9
|
+
output_dir
|
10
|
+
table_name_to_model_converter
|
11
|
+
omit_timestamps
|
11
12
|
].freeze
|
12
13
|
|
13
14
|
# timestamp
|
@@ -48,7 +49,8 @@ module Ratbug
|
|
48
49
|
ts_prefere_undefined: true, # or null
|
49
50
|
use_only_schema: false, # scan model files
|
50
51
|
output_dir: Rails.root.join('tmp', 'ratbug'),
|
51
|
-
table_name_to_model_converter: -> table_name { table_name.singularize.camelize.constantize }
|
52
|
+
table_name_to_model_converter: -> table_name { table_name.singularize.camelize.constantize },
|
53
|
+
omit_timestamps: true
|
52
54
|
}
|
53
55
|
end
|
54
56
|
end
|
@@ -11,8 +11,8 @@ module Ratbug
|
|
11
11
|
def generate
|
12
12
|
singular = @table.name.singularize
|
13
13
|
output = ""
|
14
|
-
output << "json.#{singular} do
|
15
|
-
|
14
|
+
output << "json.#{singular} do\n"
|
15
|
+
columns.values.sort_by(&:name).each do |column|
|
16
16
|
output << column_row(column, singular)
|
17
17
|
end
|
18
18
|
output << "end"
|
@@ -30,6 +30,14 @@ module Ratbug
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
+
def columns
|
34
|
+
if @options[:omit_timestamps]
|
35
|
+
@table.columns.except(:created_at, :updated_at)
|
36
|
+
else
|
37
|
+
@table.columns
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
33
41
|
def column_row(column, receiver_name)
|
34
42
|
" json.#{column.name} #{receiver_name}.#{column.name}#{column_value_modifier(column)}\n"
|
35
43
|
end
|
@@ -10,12 +10,12 @@ module Ratbug
|
|
10
10
|
|
11
11
|
def generate
|
12
12
|
output = ""
|
13
|
-
|
13
|
+
columns.values.filter { |c| c.enum.present? }.each do |column|
|
14
14
|
output << enum_output(column)
|
15
15
|
end
|
16
16
|
|
17
17
|
output << "type #{@table.name.singularize.camelize} = {\n"
|
18
|
-
|
18
|
+
columns.values.sort_by(&:name).each do |column|
|
19
19
|
output << column_row(column)
|
20
20
|
end
|
21
21
|
output << "};"
|
@@ -33,6 +33,14 @@ module Ratbug
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
+
def columns
|
37
|
+
if @options[:omit_timestamps]
|
38
|
+
@table.columns.except(:created_at, :updated_at)
|
39
|
+
else
|
40
|
+
@table.columns
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
def column_row(column)
|
37
45
|
ret = " #{column.name.camelize(:lower)}#{column.nullable ? '?' : ''}:"
|
38
46
|
if column.enum.present?
|
data/lib/ratbug/table.rb
CHANGED
@@ -6,12 +6,7 @@ module Ratbug
|
|
6
6
|
# do nothing
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
columns[:created_at] = Column.new(:datetime, 'created_at', false, nil)
|
11
|
-
columns[:updated_at] = Column.new(:datetime, 'updated_at', false, nil)
|
12
|
-
end
|
13
|
-
|
14
|
-
Column::VALID_COLUMN_TYPES.filter { |r| r != :timestamps }.each do |type|
|
9
|
+
Column::VALID_COLUMN_TYPES.each do |type|
|
15
10
|
define_method(type, -> (column_name, **options) {
|
16
11
|
comment = options['comment'] || options[:comment]
|
17
12
|
nullable = !(options['null'] == false || options[:null] == false)
|
data/lib/ratbug/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratbug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rnitta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: poor utility
|
14
14
|
email:
|