k_domain 0.0.14 → 0.0.23
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/.builders/config/_.rb +3 -0
- data/.builders/setup.rb +30 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -3
- data/Gemfile +1 -1
- data/Guardfile +1 -0
- data/README.md +15 -0
- data/STORIES.md +35 -6
- data/k_domain.gemspec +1 -1
- data/lib/k_domain/domain_model/load.rb +8 -2
- data/lib/k_domain/domain_model/transform.rb +34 -51
- data/lib/k_domain/domain_model/transform_steps/_.rb +8 -6
- data/lib/k_domain/domain_model/transform_steps/step.rb +47 -2
- data/lib/k_domain/domain_model/transform_steps/{step1_attach_db_schema.rb → step1_db_schema.rb} +2 -1
- data/lib/k_domain/domain_model/transform_steps/{step5_attach_dictionary.rb → step20_dictionary.rb} +7 -3
- data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +123 -0
- data/lib/k_domain/domain_model/transform_steps/{step8_locate_rails_models.rb → step4_rails_resource_models.rb} +4 -4
- data/lib/k_domain/domain_model/transform_steps/step5_rails_resource_routes.rb +36 -0
- data/lib/k_domain/domain_model/transform_steps/step6_rails_structure_models.rb +90 -0
- data/lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb +109 -0
- data/lib/k_domain/domain_model/transform_steps/{step3_attach_columns.rb → step8_domain_columns.rb} +40 -73
- data/lib/k_domain/rails_code_extractor/_.rb +5 -0
- data/lib/k_domain/rails_code_extractor/extract_controller.rb +59 -0
- data/lib/k_domain/rails_code_extractor/extract_model.rb +69 -0
- data/lib/k_domain/rails_code_extractor/shim_loader.rb +30 -0
- data/lib/k_domain/raw_db_schema/load.rb +8 -2
- data/lib/k_domain/raw_db_schema/transform.rb +9 -8
- data/lib/k_domain/schemas/_.rb +3 -2
- data/lib/k_domain/schemas/database.rb +86 -0
- data/lib/k_domain/schemas/domain/erd_file.rb +2 -0
- data/lib/k_domain/schemas/domain.rb +154 -0
- data/lib/k_domain/schemas/domain_model.rb +6 -5
- data/lib/k_domain/schemas/rails_resource.rb +43 -6
- data/lib/k_domain/schemas/rails_structure.rb +172 -0
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +2 -0
- data/templates/custom/action_controller.rb +36 -0
- data/templates/custom/controller_interceptors.rb +78 -0
- data/templates/custom/model_interceptors.rb +71 -0
- data/templates/load_schema.rb +7 -0
- data/templates/old_printspeek_schema copy.rb +231 -0
- data/templates/old_printspeek_schema.rb +233 -0
- data/templates/rails/action_controller.rb +301 -0
- data/templates/rails/active_record.rb +348 -0
- data/templates/ruby_code_extractor/attach_class_info.rb +13 -0
- data/templates/ruby_code_extractor/behaviour_accessors.rb +39 -0
- data/templates/simple/controller_interceptors.rb +2 -0
- metadata +30 -17
- data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +0 -62
- data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +0 -454
- data/lib/k_domain/schemas/database/_.rb +0 -7
- data/lib/k_domain/schemas/database/foreign_key.rb +0 -14
- data/lib/k_domain/schemas/database/index.rb +0 -14
- data/lib/k_domain/schemas/database/schema.rb +0 -31
- data/lib/k_domain/schemas/database/table.rb +0 -32
- data/lib/k_domain/schemas/domain/domain.rb +0 -11
- data/lib/k_domain/schemas/domain/models/column.rb +0 -49
- data/lib/k_domain/schemas/domain/models/model.rb +0 -111
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbbddfe9857696b7a3a02fc370c51205d584fd08aaad5f8b8605dccebab02bc1
|
4
|
+
data.tar.gz: c37fee293561e73b3ed4b4e31f9def8c13848217ee9c4d14efdcfc67a46d42ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12d58c761198fe6fa8336871ab5a3475c0a1caf358c09af2005e8bab3192c82b864663b867b3f2a39d8ba7c20e58258a8981ddd6339dbdb4edec73e37bca4652
|
7
|
+
data.tar.gz: 0bfd25819a3425f2932ba751d9e4413b41ae2c617416751855ced16a7fc74f68eff64d87a92138c73b85b0df175f38b8b299f5912f67f8a78970926ff83a4df8
|
data/.builders/setup.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'config/_'
|
2
|
+
require_relative "../lib/k_domain"
|
3
|
+
|
4
|
+
db_schema_ruby_file = '/Users/davidcruwys/dev/printspeak/printspeak-master/db/schema.rb'
|
5
|
+
|
6
|
+
# /Users/davidcruwys/dev/printspeak/printspeak/.builders/config/raw/schema_printspeak.rb
|
7
|
+
output_folder = File.expand_path('../.output')
|
8
|
+
db_schema_json_file = File.join(output_folder, 'db_schema.json')
|
9
|
+
schema_loader_file = File.join(output_folder, 'schema_printspeak.rb')
|
10
|
+
|
11
|
+
transformer = KDomain::RawDbSchema::Transform.new(db_schema_ruby_file)
|
12
|
+
transformer.template_file = '/Users/davidcruwys/dev/kgems/k_domain/templates/old_printspeek_schema.rb'
|
13
|
+
puts db_schema_ruby_file
|
14
|
+
puts transformer.template_file
|
15
|
+
transformer.call
|
16
|
+
transformer.write_json(db_schema_json_file)
|
17
|
+
transformer.write_schema_loader(schema_loader_file)
|
18
|
+
# transformer.schema
|
19
|
+
|
20
|
+
|
21
|
+
# transform = KDomain::DomainModel::Transform.new(
|
22
|
+
# db_schema: db_schema,
|
23
|
+
# target_file: target_file,
|
24
|
+
# target_step_file: target_step_file,
|
25
|
+
# model_path: model_path,
|
26
|
+
# controller_path: controller_path,
|
27
|
+
# route_path: route_path
|
28
|
+
# )
|
29
|
+
|
30
|
+
puts 'done'
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -6,9 +6,10 @@ AllCops:
|
|
6
6
|
NewCops: enable
|
7
7
|
Exclude:
|
8
8
|
- "_/**/*"
|
9
|
-
- "spec/
|
10
|
-
- "
|
11
|
-
- "lib/k_domain/
|
9
|
+
- "spec/example_domain/**/*"
|
10
|
+
- "templates/**/*"
|
11
|
+
- "lib/k_domain/schemas/domain/old/**/*"
|
12
|
+
- "spec/k_domain/ruby_loader/**/*"
|
12
13
|
|
13
14
|
Metrics/PerceivedComplexity:
|
14
15
|
Exclude:
|
data/Gemfile
CHANGED
@@ -28,8 +28,8 @@ end
|
|
28
28
|
if ENV['KLUE_LOCAL_GEMS']&.to_s&.downcase == 'true'
|
29
29
|
group :development, :test do
|
30
30
|
puts 'Using Local GEMs'
|
31
|
-
gem 'peeky' , path: '../peeky'
|
32
31
|
gem 'k_log' , path: '../k_log'
|
33
32
|
gem 'k_util' , path: '../k_util'
|
33
|
+
gem 'peeky' , path: '../peeky'
|
34
34
|
end
|
35
35
|
end
|
data/Guardfile
CHANGED
@@ -19,6 +19,7 @@ group :green_pass_then_cop, halt_on_fail: true do
|
|
19
19
|
# Ruby files
|
20
20
|
ruby = dsl.ruby
|
21
21
|
dsl.watch_spec_files_for(ruby.lib_files)
|
22
|
+
watch(%r{^lib/k_domain/domain_model/transform_steps/(.+).rb}) { 'spec/k_domain/domain_model/transform_spec.rb' }
|
22
23
|
watch(%r{^lib/k_domain/**/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
|
23
24
|
watch(%r{^lib/k_domain/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
|
24
25
|
end
|
data/README.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# JSON Schema
|
2
|
+
|
3
|
+
The following schemas were created using the following processes.
|
4
|
+
|
5
|
+
```
|
6
|
+
quicktype -o json-schema/database.json -t database -l schema spec/sample_output/printspeak/schema.json
|
7
|
+
quicktype -o json-schema/database.rb -t database -l ruby json-schema/database-altered.json
|
8
|
+
spec/sample_output/printspeak/schema.json
|
9
|
+
json-schema/database-altered.json
|
10
|
+
```
|
11
|
+
|
12
|
+
remove statistics
|
13
|
+
remove (or move rails structure)
|
14
|
+
drop erd_location
|
15
|
+
|
1
16
|
# K Domain
|
2
17
|
|
3
18
|
> K Domain builds complex domain schemas by combining the database schema with a rich entity relationship DSLs
|
data/STORIES.md
CHANGED
@@ -16,25 +16,54 @@ As a Developer, I can customize domain configuration, so that I can have opinion
|
|
16
16
|
|
17
17
|
- Handle traits
|
18
18
|
|
19
|
+
### Tasks next on list
|
20
|
+
|
21
|
+
BUGs in domain_model load
|
22
|
+
|
23
|
+
- spec/k_domain/domain_model/load_spec.rb:135
|
24
|
+
- FIXED: module_name should be empty
|
25
|
+
- FIXED: name mismatch (attr_accessor, attr_reader, attr_writer) in behaviours vs in (attr_accessors, attr_readers, attr_writers) functions
|
26
|
+
- functions - (attr_accessors, attr_readers, attr_writers) are all empty
|
27
|
+
|
28
|
+
External ruby process - ShimLoading and ExtractModel
|
29
|
+
|
30
|
+
- You need a clear memory foot print for shim loading and model extraction, best to run these from inside a new ruby process
|
31
|
+
|
32
|
+
Log Warning to Investigate Issues
|
33
|
+
|
34
|
+
- FIXED: All the logged warnings in k_domain need to turn up in on the investigate issues register
|
35
|
+
- Investigate needs a debug flag that when turned on, will write the issues to the console
|
36
|
+
|
37
|
+
Print progress dot
|
38
|
+
|
39
|
+
- Make this configurable
|
40
|
+
- Decide what steps this should run for
|
41
|
+
- Show step label via configuration
|
42
|
+
|
43
|
+
## Stories and tasks
|
44
|
+
|
45
|
+
### Stories - completed
|
46
|
+
|
19
47
|
As a Developer, I can read native rails model data, so that I can leverage existing rails applications for ERD modeling
|
20
48
|
|
49
|
+
- Proof of concept
|
21
50
|
- Use Meta Programming and re-implement ActiveRecord::Base
|
22
51
|
|
23
|
-
### Tasks
|
52
|
+
### Tasks - completed
|
24
53
|
|
25
54
|
Refactor / Simply
|
26
55
|
|
27
|
-
- Replace complex objects
|
56
|
+
- Replace complex objects with structs for ancillary data structures such as investigate
|
57
|
+
|
58
|
+
Steps to support write methods on base class
|
59
|
+
|
60
|
+
- Simplify lib/k_domain/domain_model/transform.rb
|
28
61
|
|
29
62
|
User acceptance testing
|
30
63
|
|
31
64
|
- Provide sample printers for each data structure to visually check data is loading
|
32
65
|
- Point raw_db_schema loader towards a complex ERD and check how it performs
|
33
66
|
|
34
|
-
## Stories and tasks
|
35
|
-
|
36
|
-
### Tasks - completed
|
37
|
-
|
38
67
|
Setup RubyGems and RubyDoc
|
39
68
|
|
40
69
|
- Build and deploy gem to [rubygems.org](https://rubygems.org/gems/k_domain)
|
data/k_domain.gemspec
CHANGED
@@ -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::Schemas::DomainModel.new(
|
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
|
@@ -11,23 +11,34 @@ module KDomain
|
|
11
11
|
attr_reader :db_schema
|
12
12
|
attr_reader :target_step_file
|
13
13
|
attr_reader :target_file
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :model_path
|
15
|
+
attr_reader :controller_path
|
16
|
+
attr_reader :route_path
|
17
|
+
attr_reader :shim_loader
|
15
18
|
|
16
|
-
|
19
|
+
# rubocop:disable Metrics/ParameterLists
|
20
|
+
def initialize(db_schema: , target_file: , target_step_file: , model_path:, route_path:, controller_path:, shim_loader: nil)
|
17
21
|
@db_schema = db_schema
|
18
22
|
@target_step_file = target_step_file
|
19
23
|
@target_file = target_file
|
20
|
-
@
|
24
|
+
@model_path = model_path
|
25
|
+
@controller_path = controller_path
|
26
|
+
@route_path = route_path
|
27
|
+
@shim_loader = shim_loader
|
21
28
|
end
|
29
|
+
# rubocop:enable Metrics/ParameterLists
|
22
30
|
|
31
|
+
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
23
32
|
def call
|
24
33
|
valid = true
|
25
|
-
valid &&=
|
26
|
-
valid &&=
|
27
|
-
valid &&=
|
28
|
-
valid &&=
|
29
|
-
valid &&=
|
30
|
-
valid &&=
|
34
|
+
valid &&= Step1DbSchema.run(domain_data, db_schema: db_schema, step_file: step_file('01-db-schema'))
|
35
|
+
valid &&= Step2DomainModels.run(domain_data, model_path: model_path, step_file: step_file('02-domain-model'))
|
36
|
+
valid &&= Step4RailsResourceModels.run(domain_data, model_path: model_path, step_file: step_file('04-rails-resource-models'))
|
37
|
+
valid &&= Step5RailsResourceRoutes.run(domain_data, route_path: route_path, controller_path: controller_path, step_file: step_file('05-rails-resource-routes'))
|
38
|
+
valid &&= Step6RailsStructureModels.run(domain_data, model_path: model_path, step_file: step_file('06-rails-structure-models'), shim_loader: shim_loader)
|
39
|
+
valid &&= Step7RailsStructureControllers.run(domain_data, controller_path: controller_path, step_file: step_file('07-rails-structure-controllers'), shim_loader: shim_loader)
|
40
|
+
valid &&= Step8DomainColumns.run(domain_data, step_file: step_file('08-domain-columns'))
|
41
|
+
valid &&= Step20Dictionary.run(domain_data, step_file: step_file('20-dictionary'))
|
31
42
|
|
32
43
|
raise 'DomainModal transform failed' unless valid
|
33
44
|
|
@@ -35,61 +46,31 @@ module KDomain
|
|
35
46
|
|
36
47
|
nil
|
37
48
|
end
|
49
|
+
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
38
50
|
|
39
|
-
def
|
40
|
-
|
41
|
-
write(step: '1-attach-db-schema')
|
51
|
+
def step_file(step_name)
|
52
|
+
format(target_step_file, step: step_name)
|
42
53
|
end
|
43
54
|
|
44
|
-
def
|
45
|
-
|
46
|
-
write(
|
47
|
-
end
|
48
|
-
|
49
|
-
def step3
|
50
|
-
Step3AttachColumns.run(domain_data)
|
51
|
-
write(step: '3-attach-columns')
|
52
|
-
end
|
53
|
-
|
54
|
-
def step4
|
55
|
-
Step4AttachErdFiles.run(domain_data, erd_path: erd_path)
|
56
|
-
write(step: '4-attach-erd-files')
|
57
|
-
end
|
58
|
-
|
59
|
-
def step5
|
60
|
-
Step5AttachDictionary.run(domain_data, erd_path: erd_path)
|
61
|
-
write(step: '5-attach-dictionary')
|
62
|
-
end
|
63
|
-
|
64
|
-
def step8
|
65
|
-
Step8LocateRailsModels.run(domain_data, erd_path: erd_path)
|
66
|
-
write(step: '8-rails-files-models')
|
67
|
-
end
|
68
|
-
|
69
|
-
def write(step: nil)
|
70
|
-
file = if step.nil?
|
71
|
-
target_file
|
72
|
-
else
|
73
|
-
format(target_step_file, step: step)
|
74
|
-
end
|
75
|
-
FileUtils.mkdir_p(File.dirname(file))
|
76
|
-
File.write(file, JSON.pretty_generate(domain_data))
|
55
|
+
def write
|
56
|
+
FileUtils.mkdir_p(File.dirname(target_file))
|
57
|
+
File.write(target_file, JSON.pretty_generate(domain_data))
|
77
58
|
end
|
78
59
|
|
60
|
+
# rubocop:disable Metrics/MethodLength
|
79
61
|
def domain_data
|
80
62
|
# The initial domain model structure is created here, but populated during the workflows.
|
81
63
|
@domain_data ||= {
|
82
64
|
domain: {
|
83
|
-
models: []
|
84
|
-
erd_files: [],
|
65
|
+
models: []
|
85
66
|
},
|
86
|
-
|
67
|
+
rails_resource: {
|
87
68
|
models: [],
|
88
|
-
|
69
|
+
routes: []
|
89
70
|
},
|
90
|
-
|
71
|
+
rails_structure: {
|
91
72
|
models: [],
|
92
|
-
controllers: []
|
73
|
+
controllers: []
|
93
74
|
},
|
94
75
|
dictionary: {
|
95
76
|
items: []
|
@@ -98,6 +79,7 @@ module KDomain
|
|
98
79
|
tables: [],
|
99
80
|
indexes: [],
|
100
81
|
foreign_keys: [],
|
82
|
+
views: [],
|
101
83
|
meta: {}
|
102
84
|
},
|
103
85
|
investigate: {
|
@@ -105,6 +87,7 @@ module KDomain
|
|
105
87
|
}
|
106
88
|
}
|
107
89
|
end
|
90
|
+
# rubocop:enable Metrics/MethodLength
|
108
91
|
end
|
109
92
|
end
|
110
93
|
end
|
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
# The require order is important due to dependencies
|
4
4
|
require_relative './step'
|
5
|
-
require_relative './
|
6
|
-
require_relative './
|
7
|
-
require_relative './
|
8
|
-
require_relative './
|
9
|
-
require_relative './
|
10
|
-
require_relative './
|
5
|
+
require_relative './step1_db_schema'
|
6
|
+
require_relative './step2_domain_models'
|
7
|
+
require_relative './step4_rails_resource_models'
|
8
|
+
require_relative './step5_rails_resource_routes'
|
9
|
+
require_relative './step6_rails_structure_models'
|
10
|
+
require_relative './step7_rails_structure_controllers'
|
11
|
+
require_relative './step8_domain_columns'
|
12
|
+
require_relative './step20_dictionary'
|
@@ -24,7 +24,8 @@ module KDomain
|
|
24
24
|
def self.run(domain_data, **opts)
|
25
25
|
step = new(domain_data, **opts)
|
26
26
|
step.call
|
27
|
-
step
|
27
|
+
step.write(opts[:step_file])
|
28
|
+
step.valid?
|
28
29
|
end
|
29
30
|
|
30
31
|
def guard(message)
|
@@ -32,6 +33,15 @@ module KDomain
|
|
32
33
|
@valid = false
|
33
34
|
end
|
34
35
|
|
36
|
+
def warning(message)
|
37
|
+
log.warn message
|
38
|
+
end
|
39
|
+
|
40
|
+
def write(file)
|
41
|
+
FileUtils.mkdir_p(File.dirname(file))
|
42
|
+
File.write(file, JSON.pretty_generate(domain_data))
|
43
|
+
end
|
44
|
+
|
35
45
|
# Domain Model Accessor/Helpers
|
36
46
|
def domain
|
37
47
|
guard('domain is missing') if domain_data[:domain].nil?
|
@@ -43,7 +53,7 @@ module KDomain
|
|
43
53
|
domain[:models]
|
44
54
|
end
|
45
55
|
|
46
|
-
# Rails File Accessor/Helpers
|
56
|
+
# Rails Resource File Accessor/Helpers
|
47
57
|
def rails_resource
|
48
58
|
guard('rails_resource is missing') if domain_data[:rails_resource].nil?
|
49
59
|
|
@@ -58,10 +68,45 @@ module KDomain
|
|
58
68
|
rails_resource[:models] = value
|
59
69
|
end
|
60
70
|
|
71
|
+
def rails_resource_routes
|
72
|
+
rails_resource[:routes]
|
73
|
+
end
|
74
|
+
|
75
|
+
def rails_resource_routes=(value)
|
76
|
+
rails_resource[:routes] = value
|
77
|
+
end
|
78
|
+
|
61
79
|
def rails_resource_controllers
|
62
80
|
rails_resource[:controllers]
|
63
81
|
end
|
64
82
|
|
83
|
+
# Rails Structure File Accessor/Helpers
|
84
|
+
def rails_structure
|
85
|
+
guard('rails_structure is missing') if domain_data[:rails_structure].nil?
|
86
|
+
|
87
|
+
domain_data[:rails_structure]
|
88
|
+
end
|
89
|
+
|
90
|
+
def rails_structure_models
|
91
|
+
rails_structure[:models]
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_rails_structure_models(model_name)
|
95
|
+
rails_structure_models.find { |model| model[:model_name] == model_name }
|
96
|
+
end
|
97
|
+
|
98
|
+
def rails_structure_models=(value)
|
99
|
+
rails_structure[:models] = value
|
100
|
+
end
|
101
|
+
|
102
|
+
def rails_structure_controllers
|
103
|
+
rails_structure[:controllers]
|
104
|
+
end
|
105
|
+
|
106
|
+
def rails_structure_controllers=(value)
|
107
|
+
rails_structure[:controllers] = value
|
108
|
+
end
|
109
|
+
|
65
110
|
# Database Accessor/Helpers
|
66
111
|
def database=(value)
|
67
112
|
domain_data[:database] = value
|
data/lib/k_domain/domain_model/transform_steps/{step1_attach_db_schema.rb → step1_db_schema.rb}
RENAMED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
module KDomain
|
4
4
|
module DomainModel
|
5
|
-
class
|
5
|
+
class Step1DbSchema < KDomain::DomainModel::Step
|
6
6
|
# Map database schema to domain model
|
7
7
|
def call
|
8
8
|
raise 'Schema not supplied' if opts[:db_schema].nil?
|
9
9
|
|
10
10
|
self.database = opts[:db_schema].clone
|
11
|
+
database[:tables] = database[:tables] # .slice(156, 1)
|
11
12
|
|
12
13
|
guard('tables are missing') if database[:tables].nil?
|
13
14
|
guard('indexes are missing') if database[:indexes].nil?
|
data/lib/k_domain/domain_model/transform_steps/{step5_attach_dictionary.rb → step20_dictionary.rb}
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
class
|
3
|
+
# data dictionary
|
4
|
+
class Step20Dictionary < KDomain::DomainModel::Step
|
5
5
|
attr_reader :dictionary
|
6
6
|
|
7
7
|
def call
|
@@ -27,7 +27,11 @@ class Step5AttachDictionary < KDomain::DomainModel::Step
|
|
27
27
|
entry[:model_count] = entry[:model_count] + 1
|
28
28
|
|
29
29
|
unless entry[:types].include?(column_type)
|
30
|
-
|
30
|
+
investigate(step: :step5_dictionary,
|
31
|
+
location: :process,
|
32
|
+
key: "#{model_name},#{column_name},#{column_type}",
|
33
|
+
message: "#{model_name} has a type mismatch for column name: #{column_name}")
|
34
|
+
|
31
35
|
entry[:types] << column_type
|
32
36
|
entry[:type_count] = entry[:type_count] + 1
|
33
37
|
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Schema is re-shaped into a format designed for domain modeling
|
4
|
+
class Step2DomainModels < KDomain::DomainModel::Step
|
5
|
+
# Map database schema to domain model
|
6
|
+
def call
|
7
|
+
raise 'Rails model path not supplied' if opts[:model_path].nil?
|
8
|
+
|
9
|
+
domain[:models] = database_tables.map { |table| model(table) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def model(table)
|
13
|
+
table_name = table[:name].to_s
|
14
|
+
model_name = table_name.singularize
|
15
|
+
|
16
|
+
model = {
|
17
|
+
name: model_name,
|
18
|
+
name_plural: table_name, # need to check if this is correct as I know it is wrong for account_history_datum
|
19
|
+
table_name: table_name,
|
20
|
+
pk: primary_key(table),
|
21
|
+
file: nil
|
22
|
+
}
|
23
|
+
|
24
|
+
attach_columns(model)
|
25
|
+
end
|
26
|
+
|
27
|
+
def primary_key(table)
|
28
|
+
{
|
29
|
+
name: table[:primary_key],
|
30
|
+
type: table[:primary_key_type],
|
31
|
+
exist: !table[:primary_key].nil?
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def attach_columns(model)
|
36
|
+
table = find_table_for_model(model)
|
37
|
+
columns = columns(table[:columns])
|
38
|
+
columns = insert_primary_key(model, columns)
|
39
|
+
model[:columns] = columns
|
40
|
+
model
|
41
|
+
end
|
42
|
+
|
43
|
+
def columns(db_columns)
|
44
|
+
db_columns.map do |db_column|
|
45
|
+
column_data(db_column[:name]).merge(
|
46
|
+
type: check_type(db_column[:type]),
|
47
|
+
precision: db_column[:precision],
|
48
|
+
scale: db_column[:scale],
|
49
|
+
default: db_column[:default],
|
50
|
+
null: db_column[:null],
|
51
|
+
limit: db_column[:limit],
|
52
|
+
array: db_column[:array]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def insert_primary_key(model, columns)
|
58
|
+
return columns unless model[:pk][:exist]
|
59
|
+
|
60
|
+
column = column_data('id').merge(
|
61
|
+
type: check_type(model[:pk][:type])
|
62
|
+
)
|
63
|
+
|
64
|
+
columns.unshift(column)
|
65
|
+
columns
|
66
|
+
end
|
67
|
+
|
68
|
+
def check_type(type)
|
69
|
+
type = type.to_sym if type.is_a?(String)
|
70
|
+
|
71
|
+
return type if %i[string integer bigint bigserial boolean float decimal datetime date hstore text jsonb].include?(type)
|
72
|
+
|
73
|
+
if type.nil?
|
74
|
+
guard('nil type detected for db_column[:type]')
|
75
|
+
|
76
|
+
return :string
|
77
|
+
end
|
78
|
+
|
79
|
+
guard("new type detected for db_column[:type] - #{type}")
|
80
|
+
|
81
|
+
camel.parse(type.to_s).downcase
|
82
|
+
end
|
83
|
+
|
84
|
+
def column_data(name)
|
85
|
+
{
|
86
|
+
name: name,
|
87
|
+
name_plural: name.pluralize,
|
88
|
+
type: nil,
|
89
|
+
precision: nil,
|
90
|
+
scale: nil,
|
91
|
+
default: nil,
|
92
|
+
null: nil,
|
93
|
+
limit: nil,
|
94
|
+
array: nil
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
# # Location of source code
|
99
|
+
# def location(table_name, model_name)
|
100
|
+
# file_normal = File.join(opts[:model_path], "#{model_name}.rb")
|
101
|
+
# file_custom = File.join(opts[:model_path], "#{table_name}.rb")
|
102
|
+
# file_exist = true
|
103
|
+
# state = []
|
104
|
+
|
105
|
+
# if File.exist?(file_normal)
|
106
|
+
# file = file_normal
|
107
|
+
# state.push(:has_ruby_model)
|
108
|
+
# elsif File.exist?(file_custom)
|
109
|
+
# file = file_custom
|
110
|
+
# state.push(:has_ruby_model)
|
111
|
+
# state.push(:nonconventional_name)
|
112
|
+
# else
|
113
|
+
# file = ''
|
114
|
+
# file_exist = false
|
115
|
+
# end
|
116
|
+
|
117
|
+
# {
|
118
|
+
# file: file,
|
119
|
+
# exist: file_exist,
|
120
|
+
# state: state
|
121
|
+
# }
|
122
|
+
# end
|
123
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Locate rails model files
|
4
|
-
class
|
4
|
+
class Step4RailsResourceModels < KDomain::DomainModel::Step
|
5
5
|
attr_accessor :ruby_code
|
6
6
|
|
7
7
|
def call
|
8
|
-
raise '
|
8
|
+
raise 'Model path not supplied' if opts[:model_path].nil?
|
9
9
|
|
10
10
|
self.rails_resource_models = domain_models.map do |model|
|
11
11
|
locate_rails_model(model[:name], model[:table_name])
|
@@ -15,8 +15,8 @@ class Step8LocateRailsModels < KDomain::DomainModel::Step
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def locate_rails_model(model_name, table_name)
|
18
|
-
file_normal = File.join(opts[:
|
19
|
-
file_custom = File.join(opts[:
|
18
|
+
file_normal = File.join(opts[:model_path], "#{model_name}.rb")
|
19
|
+
file_custom = File.join(opts[:model_path], "#{table_name}.rb")
|
20
20
|
file_exist = true
|
21
21
|
state = []
|
22
22
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Locate rails model files
|
4
|
+
class Step5RailsResourceRoutes < KDomain::DomainModel::Step
|
5
|
+
def call
|
6
|
+
return warning('Routes .json file not supplied') if opts[:route_path].nil?
|
7
|
+
return warning('Routes .json file not found') unless File.exist?(opts[:route_path])
|
8
|
+
|
9
|
+
warning('Controller path not supplied. Routes will be loaded but not paired with a controller') if opts[:controller_path].nil?
|
10
|
+
|
11
|
+
self.rails_resource_routes = load_routes(opts[:route_path], opts[:controller_path])
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def load_routes(route_path, controller_path)
|
17
|
+
json = File.read(route_path)
|
18
|
+
root = JSON.parse(json, symbolize_names: true)
|
19
|
+
routes = root[:routes]
|
20
|
+
|
21
|
+
routes.map { |route| map_route(route, controller_path) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def map_route(route, controller_path)
|
25
|
+
return route.merge({ file: '', exist: false }) if controller_path.nil?
|
26
|
+
|
27
|
+
controller_file = File.join(controller_path, route[:controller_file])
|
28
|
+
|
29
|
+
route.merge(
|
30
|
+
{
|
31
|
+
file: controller_file,
|
32
|
+
exist: File.exist?(controller_file)
|
33
|
+
}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|