k_domain 0.0.5 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -1
- data/Gemfile +10 -0
- data/Rakefile +3 -1
- data/STORIES.md +15 -0
- data/k_domain.gemspec +2 -0
- data/lib/k_domain/domain_model/load.rb +8 -2
- data/lib/k_domain/domain_model/transform.rb +30 -3
- data/lib/k_domain/domain_model/transform_steps/_.rb +2 -0
- data/lib/k_domain/domain_model/transform_steps/step.rb +38 -0
- data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +1 -1
- data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +5 -2
- data/lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb +5 -2
- data/lib/k_domain/domain_model/transform_steps/step8_rails_resource_models.rb +44 -0
- data/lib/k_domain/domain_model/transform_steps/step9_rails_structure_models.rb +33 -0
- data/lib/k_domain/rails_code_extractor/extract_model.rb +21 -0
- data/lib/k_domain/rails_code_extractor/load_shim.rb +32 -0
- data/lib/k_domain/raw_db_schema/load.rb +8 -2
- data/lib/k_domain/raw_db_schema/transform.rb +4 -5
- data/lib/k_domain/schemas/_.rb +15 -0
- data/lib/k_domain/{raw_db_schema/dtos → schemas/database}/_.rb +0 -7
- data/lib/k_domain/{raw_db_schema/dtos → schemas/database}/foreign_key.rb +1 -1
- data/lib/k_domain/{raw_db_schema/dtos → schemas/database}/index.rb +1 -1
- data/lib/k_domain/schemas/database/schema.rb +31 -0
- data/lib/k_domain/schemas/database/table.rb +32 -0
- data/lib/k_domain/schemas/dictionary.rb +19 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain}/_.rb +1 -24
- data/lib/k_domain/{domain_model/dtos → schemas/domain}/domain.rb +1 -1
- data/lib/k_domain/schemas/domain/erd_file.rb +82 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain}/models/column.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain}/models/model.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/belongs_to.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/column_old.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/domain_statistics.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/entity.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/entity_statistics.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/foreign_key.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/has_and_belongs_to_many.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/has_many.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/has_one.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/name_options.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/rails_controller.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/rails_model.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/related_entity.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/statistics.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/validate.rb +0 -0
- data/lib/k_domain/{domain_model/dtos → schemas/domain/old}/validates.rb +0 -0
- data/lib/k_domain/schemas/domain_model.rb +14 -0
- data/lib/k_domain/schemas/investigate.rb +15 -0
- data/lib/k_domain/schemas/rails_resource.rb +16 -0
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +14 -2
- data/templates/active_record_shims.rb +355 -0
- data/templates/fake_module_shims.rb +42 -0
- data/{lib/k_domain/raw_db_schema/template.rb → templates/load_schema.rb} +4 -4
- metadata +54 -35
- data/lib/k_domain/domain_model/dtos/dictionary/dictionary.rb +0 -17
- data/lib/k_domain/domain_model/dtos/investigate/investigate.rb +0 -10
- data/lib/k_domain/domain_model/dtos/investigate/issue.rb +0 -13
- data/lib/k_domain/domain_model/dtos/schema.rb +0 -12
- data/lib/k_domain/raw_db_schema/dtos/column.rb +0 -16
- data/lib/k_domain/raw_db_schema/dtos/database.rb +0 -11
- data/lib/k_domain/raw_db_schema/dtos/schema.rb +0 -18
- data/lib/k_domain/raw_db_schema/dtos/table.rb +0 -21
- data/lib/k_domain/raw_db_schema/dtos/unique_key.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98e1d3eb1435f17ad91084519399234f0adc41e399d1350071147f0e58f694c6
|
4
|
+
data.tar.gz: 2797a698e87169816a6b612239b1c22b8d2fd0db2fd6df2fc8e078fbf8828e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6cd0d3fa8354f83b5910dc961212acd0ae149b0b90c31338bf992b4f64500ae4fb05f63c605bf439d818bed8f6f4806939994c0cf8ee6fbd0c0a51d232b02f
|
7
|
+
data.tar.gz: 28d42c273b6fdae5db9b32e4cfcd4c1826e42f929efbc9713941b16bc4240cff22eed7e3260aec195beff43ae3ec20bf136bb6526988eccbd5f475c18ec2566a
|
data/.rubocop.yml
CHANGED
@@ -8,12 +8,15 @@ AllCops:
|
|
8
8
|
- "_/**/*"
|
9
9
|
- "spec/sample_input/**/*"
|
10
10
|
- "spec/sample_output/**/*"
|
11
|
-
- "
|
11
|
+
- "templates/**/*"
|
12
|
+
- "lib/k_domain/schemas/domain/old/**/*"
|
13
|
+
- "spec/k_domain/ruby_loader/**/*"
|
12
14
|
|
13
15
|
Metrics/PerceivedComplexity:
|
14
16
|
Exclude:
|
15
17
|
- "lib/k_domain/domain_model/transform_steps/*.rb"
|
16
18
|
- "lib/k_domain/domain_model/dtos/entity.rb"
|
19
|
+
- "lib/k_domain/domain_model/dtos/old/entity.rb"
|
17
20
|
|
18
21
|
Metrics/AbcSize:
|
19
22
|
Exclude:
|
@@ -21,16 +24,21 @@ Metrics/AbcSize:
|
|
21
24
|
- "lib/k_domain/domain_model/dtos/rails_model.rb"
|
22
25
|
- "lib/k_domain/domain_model/dtos/entity.rb"
|
23
26
|
- "lib/k_domain/domain_model/dtos/column_old.rb"
|
27
|
+
- "lib/k_domain/domain_model/dtos/old/column_old.rb"
|
28
|
+
- "lib/k_domain/domain_model/dtos/old/rails_model.rb"
|
29
|
+
- "lib/k_domain/domain_model/dtos/old/entity.rb"
|
24
30
|
|
25
31
|
Metrics/CyclomaticComplexity:
|
26
32
|
Exclude:
|
27
33
|
- "lib/k_domain/domain_model/transform_steps/*.rb"
|
28
34
|
- "lib/k_domain/domain_model/dtos/entity.rb"
|
35
|
+
- "lib/k_domain/domain_model/dtos/old/entity.rb"
|
29
36
|
|
30
37
|
Metrics/BlockLength:
|
31
38
|
Exclude:
|
32
39
|
- "**/spec/**/*"
|
33
40
|
- "*.gemspec"
|
41
|
+
- 'lib/k_domain/domain_model/dtos/erd_file.rb'
|
34
42
|
IgnoredMethods:
|
35
43
|
- configure
|
36
44
|
- context
|
@@ -56,6 +64,8 @@ Metrics/MethodLength:
|
|
56
64
|
Exclude:
|
57
65
|
- "lib/k_domain/domain_model/transform_steps/*.rb"
|
58
66
|
- "lib/k_domain/domain_model/dtos/rails_model.rb"
|
67
|
+
- "lib/k_domain/domain_model/dtos/old/entity.rb"
|
68
|
+
- "lib/k_domain/domain_model/dtos/old/rails_model.rb"
|
59
69
|
|
60
70
|
Layout/LineLength:
|
61
71
|
Max: 200
|
data/Gemfile
CHANGED
@@ -23,3 +23,13 @@ group :development, :test do
|
|
23
23
|
gem 'rubocop-rake', require: false
|
24
24
|
gem 'rubocop-rspec', require: false
|
25
25
|
end
|
26
|
+
|
27
|
+
# If local dependency
|
28
|
+
if ENV['KLUE_LOCAL_GEMS']&.to_s&.downcase == 'true'
|
29
|
+
group :development, :test do
|
30
|
+
puts 'Using Local GEMs'
|
31
|
+
gem 'k_log' , path: '../k_log'
|
32
|
+
gem 'k_util' , path: '../k_util'
|
33
|
+
gem 'peeky' , path: '../peeky'
|
34
|
+
end
|
35
|
+
end
|
data/Rakefile
CHANGED
data/STORIES.md
CHANGED
@@ -16,6 +16,21 @@ As a Developer, I can customize domain configuration, so that I can have opinion
|
|
16
16
|
|
17
17
|
- Handle traits
|
18
18
|
|
19
|
+
As a Developer, I can read native rails model data, so that I can leverage existing rails applications for ERD modeling
|
20
|
+
|
21
|
+
- Use Meta Programming and re-implement ActiveRecord::Base
|
22
|
+
|
23
|
+
### Tasks next on list
|
24
|
+
|
25
|
+
Refactor / Simply
|
26
|
+
|
27
|
+
- Replace complex objects an with structs for ancillary data structures such as investigate
|
28
|
+
|
29
|
+
User acceptance testing
|
30
|
+
|
31
|
+
- Provide sample printers for each data structure to visually check data is loading
|
32
|
+
- Point raw_db_schema loader towards a complex ERD and check how it performs
|
33
|
+
|
19
34
|
## Stories and tasks
|
20
35
|
|
21
36
|
### Tasks - completed
|
data/k_domain.gemspec
CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
f.match(%r{^(test|spec|features)/})
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
36
37
|
spec.bindir = 'exe'
|
37
38
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
39
|
spec.require_paths = ['lib']
|
@@ -41,4 +42,5 @@ Gem::Specification.new do |spec|
|
|
41
42
|
spec.add_dependency 'activesupport' , '~> 6'
|
42
43
|
spec.add_dependency 'dry-struct', '~> 1'
|
43
44
|
spec.add_dependency 'k_log' , '~> 0.0.0'
|
45
|
+
spec.add_dependency 'peeky' , '~> 0.0.0'
|
44
46
|
end
|
@@ -20,9 +20,15 @@ module KDomain
|
|
20
20
|
|
21
21
|
def call
|
22
22
|
json = File.read(source_file)
|
23
|
-
|
23
|
+
@raw_data = KUtil.data.json_parse(json, as: :hash_symbolized)
|
24
24
|
|
25
|
-
@data = KDomain::DomainModel
|
25
|
+
@data = KDomain::Schemas::DomainModel.new(@raw_data)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_h
|
29
|
+
return nil unless defined? @raw_data
|
30
|
+
|
31
|
+
@raw_data
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -13,13 +13,14 @@ module KDomain
|
|
13
13
|
attr_reader :target_file
|
14
14
|
attr_reader :erd_path
|
15
15
|
|
16
|
-
def initialize(db_schema, target_file, target_step_file, erd_path)
|
16
|
+
def initialize(db_schema: , target_file: , target_step_file: , erd_path:)
|
17
17
|
@db_schema = db_schema
|
18
18
|
@target_step_file = target_step_file
|
19
19
|
@target_file = target_file
|
20
20
|
@erd_path = erd_path
|
21
21
|
end
|
22
22
|
|
23
|
+
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
23
24
|
def call
|
24
25
|
valid = true
|
25
26
|
valid &&= step1
|
@@ -27,6 +28,8 @@ module KDomain
|
|
27
28
|
valid &&= step3
|
28
29
|
valid &&= step4
|
29
30
|
valid &&= step5
|
31
|
+
valid &&= step8
|
32
|
+
valid &&= step9
|
30
33
|
|
31
34
|
raise 'DomainModal transform failed' unless valid
|
32
35
|
|
@@ -34,6 +37,7 @@ module KDomain
|
|
34
37
|
|
35
38
|
nil
|
36
39
|
end
|
40
|
+
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
37
41
|
|
38
42
|
def step1
|
39
43
|
Step1AttachDbSchema.run(domain_data, db_schema: db_schema)
|
@@ -60,6 +64,16 @@ module KDomain
|
|
60
64
|
write(step: '5-attach-dictionary')
|
61
65
|
end
|
62
66
|
|
67
|
+
def step8
|
68
|
+
Step8RailsResourceModels.run(domain_data, erd_path: erd_path)
|
69
|
+
write(step: '8-rails-resource-models')
|
70
|
+
end
|
71
|
+
|
72
|
+
def step9
|
73
|
+
Step9RailsStructureModels.run(domain_data, erd_path: erd_path)
|
74
|
+
write(step: '8-rails-structure-models')
|
75
|
+
end
|
76
|
+
|
63
77
|
def write(step: nil)
|
64
78
|
file = if step.nil?
|
65
79
|
target_file
|
@@ -70,13 +84,24 @@ module KDomain
|
|
70
84
|
File.write(file, JSON.pretty_generate(domain_data))
|
71
85
|
end
|
72
86
|
|
87
|
+
# rubocop:disable Metrics/MethodLength
|
73
88
|
def domain_data
|
74
89
|
# The initial domain model structure is created here, but populated during the workflows.
|
75
90
|
@domain_data ||= {
|
76
91
|
domain: {
|
77
92
|
models: [],
|
78
|
-
erd_files: []
|
79
|
-
|
93
|
+
erd_files: []
|
94
|
+
},
|
95
|
+
rails_resource: {
|
96
|
+
models: [],
|
97
|
+
controllers: []
|
98
|
+
},
|
99
|
+
rails_structure: {
|
100
|
+
models: [],
|
101
|
+
controllers: []
|
102
|
+
},
|
103
|
+
dictionary: {
|
104
|
+
items: []
|
80
105
|
},
|
81
106
|
database: {
|
82
107
|
tables: [],
|
@@ -89,6 +114,8 @@ module KDomain
|
|
89
114
|
}
|
90
115
|
}
|
91
116
|
end
|
117
|
+
|
118
|
+
# rubocop:enable Metrics/MethodLength
|
92
119
|
end
|
93
120
|
end
|
94
121
|
end
|
@@ -7,3 +7,5 @@ require_relative './step2_attach_models'
|
|
7
7
|
require_relative './step3_attach_columns'
|
8
8
|
require_relative './step4_attach_erd_files'
|
9
9
|
require_relative './step5_attach_dictionary'
|
10
|
+
require_relative './step8_rails_resource_models'
|
11
|
+
require_relative './step9_rails_structure_models'
|
@@ -43,6 +43,44 @@ module KDomain
|
|
43
43
|
domain[:models]
|
44
44
|
end
|
45
45
|
|
46
|
+
# Rails Resource File Accessor/Helpers
|
47
|
+
def rails_resource
|
48
|
+
guard('rails_resource is missing') if domain_data[:rails_resource].nil?
|
49
|
+
|
50
|
+
domain_data[:rails_resource]
|
51
|
+
end
|
52
|
+
|
53
|
+
def rails_resource_models
|
54
|
+
rails_resource[:models]
|
55
|
+
end
|
56
|
+
|
57
|
+
def rails_resource_models=(value)
|
58
|
+
rails_resource[:models] = value
|
59
|
+
end
|
60
|
+
|
61
|
+
def rails_resource_controllers
|
62
|
+
rails_resource[:controllers]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Rails Structure File Accessor/Helpers
|
66
|
+
def rails_structure
|
67
|
+
guard('rails_structure is missing') if domain_data[:rails_structure].nil?
|
68
|
+
|
69
|
+
domain_data[:rails_structure]
|
70
|
+
end
|
71
|
+
|
72
|
+
def rails_structure_models
|
73
|
+
rails_structure[:models]
|
74
|
+
end
|
75
|
+
|
76
|
+
def rails_structure_models=(value)
|
77
|
+
rails_structure[:models] = value
|
78
|
+
end
|
79
|
+
|
80
|
+
def rails_structure_controllers
|
81
|
+
rails_structure[:controllers]
|
82
|
+
end
|
83
|
+
|
46
84
|
# Database Accessor/Helpers
|
47
85
|
def database=(value)
|
48
86
|
domain_data[:database] = value
|
@@ -13,7 +13,7 @@ module KDomain
|
|
13
13
|
guard('indexes are missing') if database[:indexes].nil?
|
14
14
|
guard('foreign keys are missing') if database[:foreign_keys].nil?
|
15
15
|
guard('rails version is missing') if database[:meta][:rails].nil?
|
16
|
-
guard('postgres extensions are missing') if database[:meta][:
|
16
|
+
guard('postgres extensions are missing') if database[:meta][:db_info][:extensions].nil?
|
17
17
|
guard('unique keys are missing') if database[:meta][:unique_keys].nil?
|
18
18
|
end
|
19
19
|
end
|
@@ -24,6 +24,9 @@ class Step4AttachErdFiles < KDomain::DomainModel::Step
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def load_dsl(model)
|
27
|
+
# this should be a configuration
|
28
|
+
# print '.'
|
29
|
+
|
27
30
|
reset_dsl
|
28
31
|
|
29
32
|
dsl[:name] = model[:name]
|
@@ -58,7 +61,7 @@ class Step4AttachErdFiles < KDomain::DomainModel::Step
|
|
58
61
|
ruby: ruby_code,
|
59
62
|
public: public_code,
|
60
63
|
private: private_code,
|
61
|
-
|
64
|
+
all_methods: grab_methods(public_code, private_code)
|
62
65
|
}
|
63
66
|
end
|
64
67
|
|
@@ -348,7 +351,7 @@ class Step4AttachErdFiles < KDomain::DomainModel::Step
|
|
348
351
|
instance_private = all_instance.select { |method| method[:scope] == :private }
|
349
352
|
|
350
353
|
{
|
351
|
-
|
354
|
+
klass: class_methods,
|
352
355
|
instance: all_instance,
|
353
356
|
instance_public: instance_public,
|
354
357
|
instance_private: instance_private
|
@@ -13,7 +13,9 @@ class Step5AttachDictionary < KDomain::DomainModel::Step
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
domain_data[:dictionary] = {
|
17
|
+
items: dictionary.values
|
18
|
+
}
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
@@ -25,7 +27,8 @@ class Step5AttachDictionary < KDomain::DomainModel::Step
|
|
25
27
|
entry[:model_count] = entry[:model_count] + 1
|
26
28
|
|
27
29
|
unless entry[:types].include?(column_type)
|
28
|
-
|
30
|
+
# ADD to investigate
|
31
|
+
# log.warn("#{model_name} has a type mismatch for column name: #{column_name}")
|
29
32
|
entry[:types] << column_type
|
30
33
|
entry[:type_count] = entry[:type_count] + 1
|
31
34
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Locate rails model files
|
4
|
+
class Step8RailsResourceModels < KDomain::DomainModel::Step
|
5
|
+
attr_accessor :ruby_code
|
6
|
+
|
7
|
+
def call
|
8
|
+
raise 'ERD path not supplied' if opts[:erd_path].nil?
|
9
|
+
|
10
|
+
self.rails_resource_models = domain_models.map do |model|
|
11
|
+
locate_rails_model(model[:name], model[:table_name])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def locate_rails_model(model_name, table_name)
|
18
|
+
file_normal = File.join(opts[:erd_path], "#{model_name}.rb")
|
19
|
+
file_custom = File.join(opts[:erd_path], "#{table_name}.rb")
|
20
|
+
file_exist = true
|
21
|
+
state = []
|
22
|
+
|
23
|
+
if File.exist?(file_normal)
|
24
|
+
file = file_normal
|
25
|
+
state.push(:has_ruby_model)
|
26
|
+
elsif File.exist?(file_custom)
|
27
|
+
file = file_custom
|
28
|
+
state.push(:has_ruby_model)
|
29
|
+
state.push(:non_conventional_name)
|
30
|
+
else
|
31
|
+
file = ''
|
32
|
+
file_exist = false
|
33
|
+
state.push(:model_not_found)
|
34
|
+
end
|
35
|
+
|
36
|
+
{
|
37
|
+
model_name: model_name,
|
38
|
+
table_name: table_name,
|
39
|
+
file: file,
|
40
|
+
exist: file_exist,
|
41
|
+
state: state.join(', ')
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Locate rails model files
|
4
|
+
class Step9RailsStructureModels < KDomain::DomainModel::Step
|
5
|
+
attr_accessor :ruby_code
|
6
|
+
|
7
|
+
def call
|
8
|
+
raise 'ERD path not supplied' if opts[:erd_path].nil?
|
9
|
+
|
10
|
+
self.rails_structure_models = rails_resource_models.map do |resource|
|
11
|
+
process_resource(OpenStruct.new(resource))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def process_resource(resource)
|
18
|
+
erd_path = opts[:erd_path]
|
19
|
+
puts erd_path
|
20
|
+
@model = {
|
21
|
+
model_name: resource.model_name,
|
22
|
+
table_name: resource.table_name,
|
23
|
+
file: resource.file,
|
24
|
+
exist: resource.exist,
|
25
|
+
state: resource.state,
|
26
|
+
code: resource.exist ? File.read(resource.file) : '',
|
27
|
+
behaviours: {},
|
28
|
+
functions: {}
|
29
|
+
}
|
30
|
+
|
31
|
+
@model
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Takes a Rails Model and extracts DSL behaviours and custom functions (instance, class and private methods)
|
4
|
+
module KDomain
|
5
|
+
module RailsCodeExtractor
|
6
|
+
class ExtractModel
|
7
|
+
include KLog::Logging
|
8
|
+
|
9
|
+
attr_reader :source_file
|
10
|
+
attr_reader :data
|
11
|
+
|
12
|
+
def initialize(source_file)
|
13
|
+
@source_file = source_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
log.kv 'source_file', source_file
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Code extraction requires shims to be loaded before extraction
|
4
|
+
#
|
5
|
+
# This shims server two purposes
|
6
|
+
#
|
7
|
+
# 1. Inject data capture methods calls that intercept DSL macros so that data can be extracted
|
8
|
+
# 2. Inject fake module/classes that would otherwise break code loading with various exceptions
|
9
|
+
module KDomain
|
10
|
+
module RailsCodeExtractor
|
11
|
+
class LoadShim
|
12
|
+
include KLog::Logging
|
13
|
+
|
14
|
+
attr_reader :shim_files
|
15
|
+
|
16
|
+
attr_reader :dsl_shim_file
|
17
|
+
attr_reader :fake_module_file
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@shim_files = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
log.kv 'preload', preload
|
25
|
+
end
|
26
|
+
|
27
|
+
def register(name, file)
|
28
|
+
@shim_files << { name: name, file: file, exist: File.exist?(file) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -20,9 +20,15 @@ module KDomain
|
|
20
20
|
|
21
21
|
def call
|
22
22
|
json = File.read(source_file)
|
23
|
-
|
23
|
+
@raw_data = KUtil.data.json_parse(json, as: :hash_symbolized)
|
24
24
|
|
25
|
-
@data = KDomain::
|
25
|
+
@data = KDomain::Database::Schema.new(@raw_data)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_h
|
29
|
+
return nil unless defined? @raw_data
|
30
|
+
|
31
|
+
@raw_data
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -14,10 +14,9 @@ module KDomain
|
|
14
14
|
attr_reader :template_file
|
15
15
|
attr_reader :schema_loader
|
16
16
|
|
17
|
-
# , target_file)
|
18
17
|
def initialize(source_file)
|
19
18
|
@source_file = source_file
|
20
|
-
@template_file = '
|
19
|
+
@template_file = KDomain::Gem.resource('templates/load_schema.rb')
|
21
20
|
end
|
22
21
|
|
23
22
|
def call
|
@@ -25,7 +24,6 @@ module KDomain
|
|
25
24
|
# log.kv 'template_file', template_file
|
26
25
|
# log.kv 'source_file?', File.exist?(source_file)
|
27
26
|
# log.kv 'template_file?', File.exist?(template_file)
|
28
|
-
|
29
27
|
log.error "Template not found: #{template_file}" unless File.exist?(template_file)
|
30
28
|
|
31
29
|
content = File.read(source_file)
|
@@ -70,12 +68,13 @@ module KDomain
|
|
70
68
|
return
|
71
69
|
end
|
72
70
|
|
73
|
-
#
|
74
|
-
eval schema_loader
|
71
|
+
eval(schema_loader) # , __FILE__, __LINE__)
|
75
72
|
|
76
73
|
loader = LoadSchema.new
|
77
74
|
loader.load_schema
|
78
75
|
loader.schema
|
76
|
+
rescue StandardError => e
|
77
|
+
log.exception(e)
|
79
78
|
end
|
80
79
|
# rubocop:enable Security/Eval
|
81
80
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# log.warn 'models->domain' if AppDebug.require?
|
4
|
+
|
5
|
+
module Types
|
6
|
+
include Dry.Types()
|
7
|
+
end
|
8
|
+
|
9
|
+
require_relative 'rails_resource'
|
10
|
+
require_relative 'investigate'
|
11
|
+
require_relative 'database/_'
|
12
|
+
require_relative 'dictionary'
|
13
|
+
require_relative 'domain/_'
|
14
|
+
|
15
|
+
require_relative './domain_model'
|
@@ -1,14 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Types
|
4
|
-
include Dry.Types()
|
5
|
-
end
|
6
|
-
|
7
3
|
# The require order is important due to dependencies
|
8
|
-
require_relative './column'
|
9
|
-
require_relative './database'
|
10
4
|
require_relative './index'
|
11
5
|
require_relative './table'
|
12
6
|
require_relative './foreign_key'
|
13
|
-
require_relative './unique_key'
|
14
7
|
require_relative './schema'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module Database
|
5
|
+
class Schema < Dry::Struct
|
6
|
+
class DbInfo < Dry::Struct
|
7
|
+
attribute :type , Types::Strict::String
|
8
|
+
attribute :version , Types::Nominal::Any.optional.default(nil)
|
9
|
+
attribute :extensions , Types::Strict::Array
|
10
|
+
end
|
11
|
+
|
12
|
+
class UniqueKey < Dry::Struct
|
13
|
+
attribute :type , Types::Strict::String
|
14
|
+
attribute :category , Types::Strict::String.optional
|
15
|
+
attribute :key , Types::Strict::String
|
16
|
+
attribute :keys , Types::Strict::Array
|
17
|
+
end
|
18
|
+
|
19
|
+
class Meta < Dry::Struct
|
20
|
+
attribute :rails , Types::Strict::Integer
|
21
|
+
attribute :db_info , KDomain::Database::Schema::DbInfo
|
22
|
+
attribute :unique_keys , Types::Strict::Array.of(KDomain::Database::Schema::UniqueKey)
|
23
|
+
end
|
24
|
+
|
25
|
+
attribute :tables , Types::Strict::Array.of(KDomain::Database::Table)
|
26
|
+
attribute :foreign_keys? , Types::Strict::Array.of(KDomain::Database::ForeignKey)
|
27
|
+
attribute :indexes? , Types::Strict::Array.of(KDomain::Database::Index)
|
28
|
+
attribute :meta , KDomain::Database::Schema::Meta
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module Database
|
5
|
+
class Table < Dry::Struct
|
6
|
+
class RailsSchema < Dry::Struct
|
7
|
+
attribute :primary_key , Types::Nominal::Any.optional.default(nil)
|
8
|
+
attribute :id , Types::Nominal::Any.optional.default(nil)
|
9
|
+
attribute :force , Types::Nominal::Any.optional.default(nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Column < Dry::Struct
|
13
|
+
attribute :name , Types::Strict::String
|
14
|
+
attribute :type , Types::Strict::String
|
15
|
+
attribute :precision? , Types::Strict::Integer.optional.default(nil)
|
16
|
+
attribute :scale? , Types::Strict::Integer.optional.default(nil)
|
17
|
+
attribute :default? , Types::Nominal::Any.optional.default(nil)
|
18
|
+
attribute :array? , Types::Strict::Bool.optional.default(nil)
|
19
|
+
attribute :null? , Types::Strict::Bool.optional.default(nil)
|
20
|
+
attribute :limit? , Types::Strict::Integer.optional.default(nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
attribute :name , Types::Strict::String
|
24
|
+
attribute :primary_key , Types::Strict::String.optional.default(nil)
|
25
|
+
attribute :primary_key_type , Types::Strict::String.optional.default(nil)
|
26
|
+
attribute :id? , Types::Nominal::Any.optional.default(nil)
|
27
|
+
attribute :columns , Types::Strict::Array.of(KDomain::Database::Table::Column)
|
28
|
+
attribute :indexes , Types::Strict::Array.of(KDomain::Database::Index) # May want to have a Table::Index, but for now this is a shared scheam
|
29
|
+
attribute :rails_schema , KDomain::Database::Table::RailsSchema
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain class holds a dictionary entry
|
4
|
+
module KDomain
|
5
|
+
module Schemas
|
6
|
+
class Dictionary < Dry::Struct
|
7
|
+
attribute :items , Types::Strict::Array do
|
8
|
+
attribute :name , Types::Strict::String
|
9
|
+
attribute :type , Types::Strict::String
|
10
|
+
attribute :label , Types::Strict::String
|
11
|
+
attribute :segment , Types::Strict::String
|
12
|
+
attribute :models , Types::Strict::Array
|
13
|
+
attribute :model_count , Types::Strict::Integer
|
14
|
+
attribute :types , Types::Strict::Array
|
15
|
+
attribute :type_count , Types::Strict::Integer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|