k_domain 0.0.27 → 0.0.28

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: 56185cb3b21dcdc594e86e2f90a5700705e308210cf531371d717798ee7762c4
4
- data.tar.gz: ec39dc47a6b40b875134431205d7d8da54e83aa7a1818c352dcde485e5f31682
3
+ metadata.gz: 2206bc03f809354e7cacb541a081491e1ce06c8eb82eb655cd81fdc7d16a69e7
4
+ data.tar.gz: 9e5f99803fee97745f11e870b79039510e0b0c733d43191c1cf5557d8e138b65
5
5
  SHA512:
6
- metadata.gz: 639891b42099979c7955fa0586bc8e408900c97a3b0f4197704dd0f4e05765679b80ba83926c9b3c4307e8154f830ef90a4793097901007b11710f93010e1c04
7
- data.tar.gz: 37c2f1076fddfd3c01da39dada2c579f62cda2af50aa1ba0105184c93c9f1442e4ec66d86e154b02d997310ec09d182991e9a054e5e340759bb11eead4d296bb
6
+ metadata.gz: 2576e2e9f17587883e1edea8b8b32cbab53530574657511870de4bb679cb0b32822970937efab04ee7ca15a689ec8b3ffaf7856872e96e9696a8775ce00aaf8d
7
+ data.tar.gz: ecd8d2f12229d9cf422515be37091ee8e13b893712f7ba15e236a515319b31b301fb468ab75e6034233cd028bb0cc0c98e0216d9c12bbae60b4a66f20584e8db
data/Gemfile CHANGED
@@ -16,7 +16,7 @@ group :development, :test do
16
16
  gem 'guard-bundler'
17
17
  gem 'guard-rspec'
18
18
  gem 'guard-rubocop'
19
- gem 'rake', '~> 12.0'
19
+ gem 'rake'
20
20
  gem 'rake-compiler', require: false
21
21
  gem 'rspec', '~> 3.0'
22
22
  gem 'rubocop'
@@ -9,10 +9,10 @@ module KDomain
9
9
  include KLog::Logging
10
10
 
11
11
  attr_reader :db_schema
12
- attr_reader :target_step_file
12
+ attr_reader :target_folder
13
13
  attr_reader :query
14
14
 
15
- def initialize(domain_model: , target_folder:)
15
+ def initialize(domain_model:, target_folder:)
16
16
  @domain_model = domain_model
17
17
  @target_folder = target_folder
18
18
  @query = KDomain::Queries::DomainModelQuery.new(domain_model)
@@ -21,17 +21,21 @@ module KDomain
21
21
  def call
22
22
  FileUtils.mkdir_p(target_folder)
23
23
 
24
- export_domain_models(query.all.take(3))
24
+ export_domain_models(query.all) # .take(3))
25
25
  end
26
26
 
27
27
  def export_domain_models(models)
28
+ puts 'export domain models'
28
29
  models.each do |model|
30
+ # write a single dot to the console in the color red
31
+ print "\e[31m.\e[0m"
32
+
29
33
  json = JSON.pretty_generate(build_rich_model(model))
30
- target_file = File.join(target_folder, model.name + '.json')
34
+ target_file = File.join(target_folder, "#{model.name}.json")
31
35
  File.write(target_file, json)
32
36
  end
33
37
  end
34
-
38
+
35
39
  def build_rich_model(model)
36
40
  {
37
41
  name: model.name,
@@ -41,8 +45,23 @@ module KDomain
41
45
  pk: model.pk.to_h,
42
46
  file: model.file,
43
47
  exist: model.ruby?,
48
+ create_update_timestamp: model.create_update_timestamp?,
44
49
  main_key: model.main_key,
45
50
  traits: model.traits,
51
+ column_names: {
52
+ all: model.columns.map(&:name),
53
+ data: model.columns_data.map(&:name),
54
+ primary: model.columns_primary.map(&:name),
55
+ foreign_key: model.columns_foreign_key.map(&:name),
56
+ foreign_type: model.columns_foreign_type.map(&:name),
57
+ timestamp: model.columns_timestamp.map(&:name),
58
+ deleted_at: model.columns_deleted_at.map(&:name),
59
+ virtual: model.columns_virtual.map(&:name),
60
+ data_foreign: model.columns_data_foreign.map(&:name),
61
+ data_primary: model.columns_data_primary.map(&:name),
62
+ data_virtual: model.columns_data_virtual.map(&:name),
63
+ data_foreign_virtual: model.columns_data_foreign_virtual.map(&:name)
64
+ },
46
65
  columns: {
47
66
  all: model.columns.map(&:to_h),
48
67
  data: model.columns_data.map(&:to_h),
@@ -47,6 +47,41 @@ module KDomain
47
47
 
48
48
  @csharp_type = KDomain::Schemas::CSHARP_TYPE[type] || '******'
49
49
  end
50
+
51
+ def to_h
52
+ {
53
+ name: name,
54
+ name_plural: name_plural,
55
+ type: type,
56
+ precision: precision,
57
+ scale: scale,
58
+ default: default,
59
+ default_as_code: value_as_code(default),
60
+ null: null,
61
+ null_as_code: value_as_code(null), # handlebars does not like null property name
62
+ limit: limit,
63
+ array: array,
64
+ array_as_code: value_as_code(array),
65
+ db_type: db_type,
66
+ ruby_type: ruby_type,
67
+ csharp_type: csharp_type,
68
+ structure_type: structure_type,
69
+ relationships: relationships
70
+ }
71
+ end
72
+
73
+ private
74
+
75
+ def value_as_code(value)
76
+ return value if value.nil?
77
+
78
+ case value
79
+ when String # , Hash
80
+ "'#{value}'"
81
+ else
82
+ value.to_s
83
+ end
84
+ end
50
85
  end
51
86
 
52
87
  class Pk < Dry::Struct
@@ -79,6 +114,12 @@ module KDomain
79
114
  pk.exist
80
115
  end
81
116
 
117
+ def create_update_timestamp?
118
+ names = columns_timestamp.map(&:name)
119
+
120
+ (names & %w[created_at updated_at]).any?
121
+ end
122
+
82
123
  # Custom model configurations such as main_key and traits
83
124
  def config
84
125
  @config ||= KDomain.configuration.find_model(name.to_sym)
@@ -105,6 +146,7 @@ module KDomain
105
146
  @columns_foreign ||= columns_for_structure_types(:foreign_key)
106
147
  end
107
148
 
149
+ # polymorphic foreign keys
108
150
  def columns_foreign_type
109
151
  @columns_foreign_type ||= columns_for_structure_types(:foreign_type)
110
152
  end
@@ -122,7 +164,7 @@ module KDomain
122
164
  end
123
165
 
124
166
  def columns_data_foreign
125
- @columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key)
167
+ @columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key, :foreign_type)
126
168
  end
127
169
  alias rows_fields_and_fk columns_data_foreign
128
170
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDomain
4
- VERSION = '0.0.27'
4
+ VERSION = '0.0.28'
5
5
  end
@@ -11,11 +11,32 @@ module ActsAsCommentable
11
11
  end
12
12
  end
13
13
 
14
+
14
15
  module Scopes
15
16
  module CompanyScopes
16
17
  end
17
18
  end
18
19
 
20
+ module DeIdentifiable
21
+ def deidentifiable(*_p, **_o); end
22
+ end
23
+
24
+ class Company < ActiveRecord::Base
25
+ extend DeIdentifiable
26
+ end
27
+ class Estimate < ActiveRecord::Base
28
+ extend DeIdentifiable
29
+ end
30
+ class Invoice < ActiveRecord::Base
31
+ extend DeIdentifiable
32
+ end
33
+ class Address < ActiveRecord::Base
34
+ extend DeIdentifiable
35
+ end
36
+ class Contact < ActiveRecord::Base
37
+ extend DeIdentifiable
38
+ end
39
+
19
40
  class Thread
20
41
  def initialize(*_p, **_o, &block); end
21
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-11 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  requirements: []
185
- rubygems_version: 3.2.33
185
+ rubygems_version: 3.1.6
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: K Domain builds complex domain schemas by combining the database schema with