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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8455d102f08a34f1a91cbb925729a7e8a1fac0d94bb5967156c67253c1db8ff
4
- data.tar.gz: ce78a895586d2b98962e6560719fffbdfd3aef4165feceaf8ee79e259d68c275
3
+ metadata.gz: 79527c57486065571d60fa01210d87af021ac78888f8ea28faef6eb84ab1ad49
4
+ data.tar.gz: aa8e3c50dcb21b66b5d87117516984cf79a665a25ef335c83aca4196c121c118
5
5
  SHA512:
6
- metadata.gz: bb75ca8bf44fc5e1b9211e3b0ba435376daf2e4ed1424c9d69bc7aee6f9c024d23f09be5db09d2e2d7a1ba77e70bf174bbe7c0b0efef29c4767e0f245e2d6e6a
7
- data.tar.gz: 2075780d7cfe7eb60a40a242bd8be1aec8e723d0b096326f32877875fe42ae3dce5d43f65ac3ebf81e83c0bdbbff85470d6e346ce6884c1b18464632ad4e159d
6
+ metadata.gz: 555c1c504c7ea332a1e05b674431761fcdb691f58b318128a7433159ea84b0880d09389e666f503629612611d25fe3303a6e88a8b48e6b92146ff36fcc683bd2
7
+ data.tar.gz: 50a95300d9dead24e0f13d926ca794f040b9d9afbeae977baaefb137caf763474929eaa9742a1b704d6b66675ab22dde27a24d949a347fb794b86b6340de9c17
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ratbug (0.0.1)
4
+ ratbug (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,13 +1,14 @@
1
1
  module Ratbug
2
2
  class GenerateConfig
3
3
  VALID_OPTION_KEYS = %i[
4
- enabled_outputs
5
- ts_prefer_type
6
- ts_enum_output_type
7
- ts_prefere_undefined
8
- use_only_schema
9
- output_dir
10
- table_name_to_model_converter
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 |#{singular}|\n"
15
- @table.columns.values.sort_by(&:name).each do |column|
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
- @table.columns.values.filter { |c| c.enum.present? }.each do |column|
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
- @table.columns.values.sort_by(&:name).each do |column|
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
- def timestamps(*,**)
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)
@@ -1,3 +1,3 @@
1
1
  module Ratbug
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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.1
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-10 00:00:00.000000000 Z
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: poor utility
14
14
  email: