k_domain 0.0.20 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.builders/boot.rb +40 -0
  3. data/.builders/generators/configuration_generator.rb +22 -0
  4. data/.builders/run.rb +16 -0
  5. data/.github/workflows/main.yml +5 -3
  6. data/.gitignore +2 -0
  7. data/.rubocop.yml +9 -5
  8. data/Gemfile +1 -1
  9. data/Guardfile +1 -0
  10. data/README.md +15 -0
  11. data/k_domain.gemspec +1 -1
  12. data/lib/k_domain/config/_.rb +4 -0
  13. data/lib/k_domain/config/config.rb +19 -0
  14. data/lib/k_domain/config/configuration.rb +76 -0
  15. data/lib/k_domain/domain_model/build_rich_models.rb +64 -0
  16. data/lib/k_domain/domain_model/load.rb +44 -1
  17. data/lib/k_domain/domain_model/transform.rb +28 -16
  18. data/lib/k_domain/domain_model/transform_steps/_.rb +7 -5
  19. data/lib/k_domain/domain_model/transform_steps/step.rb +20 -0
  20. data/lib/k_domain/domain_model/transform_steps/{step1_attach_db_schema.rb → step1_db_schema.rb} +2 -1
  21. data/lib/k_domain/domain_model/transform_steps/{step6_attach_dictionary.rb → step20_dictionary.rb} +6 -6
  22. data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +123 -0
  23. data/lib/k_domain/domain_model/transform_steps/step4_rails_resource_models.rb +3 -3
  24. data/lib/k_domain/domain_model/transform_steps/step5_rails_resource_routes.rb +36 -0
  25. data/lib/k_domain/domain_model/transform_steps/step6_rails_structure_models.rb +91 -0
  26. data/lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb +114 -0
  27. data/lib/k_domain/domain_model/transform_steps/step8_domain_columns.rb +99 -0
  28. data/lib/k_domain/queries/_.rb +4 -0
  29. data/lib/k_domain/queries/base_query.rb +13 -0
  30. data/lib/k_domain/queries/domain_model_query.rb +88 -0
  31. data/lib/k_domain/rails_code_extractor/_.rb +5 -0
  32. data/lib/k_domain/rails_code_extractor/extract_controller.rb +61 -0
  33. data/lib/k_domain/rails_code_extractor/extract_model.rb +21 -8
  34. data/lib/k_domain/rails_code_extractor/shim_loader.rb +4 -1
  35. data/lib/k_domain/raw_db_schema/load.rb +1 -1
  36. data/lib/k_domain/raw_db_schema/transform.rb +28 -3
  37. data/lib/k_domain/schemas/_.rb +5 -3
  38. data/lib/k_domain/schemas/database.rb +86 -0
  39. data/lib/k_domain/schemas/domain/erd_file.rb +78 -77
  40. data/lib/k_domain/schemas/domain.rb +153 -0
  41. data/lib/k_domain/schemas/{domain/_.rb → domain_types.rb} +1 -8
  42. data/lib/k_domain/schemas/{domain_model.rb → main_dataset.rb} +4 -4
  43. data/lib/k_domain/schemas/rails_resource.rb +43 -6
  44. data/lib/k_domain/schemas/rails_structure.rb +104 -14
  45. data/lib/k_domain/version.rb +1 -1
  46. data/lib/k_domain.rb +7 -3
  47. data/templates/custom/action_controller.rb +7 -0
  48. data/templates/custom/controller_interceptors.rb +80 -0
  49. data/templates/custom/model_interceptors.rb +95 -0
  50. data/templates/load_schema.rb +7 -0
  51. data/templates/rails/action_controller.rb +301 -0
  52. data/templates/{active_record_shims.rb → rails/active_record.rb} +23 -41
  53. data/templates/ruby_code_extractor/attach_class_info.rb +13 -0
  54. data/templates/ruby_code_extractor/behaviour_accessors.rb +39 -0
  55. data/templates/sample_config.rb +47 -0
  56. data/templates/simple/controller_interceptors.rb +2 -0
  57. metadata +36 -21
  58. data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +0 -62
  59. data/lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb +0 -137
  60. data/lib/k_domain/domain_model/transform_steps/step5_rails_models.rb +0 -71
  61. data/lib/k_domain/schemas/database/_.rb +0 -7
  62. data/lib/k_domain/schemas/database/foreign_key.rb +0 -14
  63. data/lib/k_domain/schemas/database/index.rb +0 -14
  64. data/lib/k_domain/schemas/database/schema.rb +0 -31
  65. data/lib/k_domain/schemas/database/table.rb +0 -32
  66. data/lib/k_domain/schemas/domain/domain.rb +0 -11
  67. data/lib/k_domain/schemas/domain/models/column.rb +0 -49
  68. data/lib/k_domain/schemas/domain/models/model.rb +0 -111
  69. data/templates/fake_module_shims.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de5fc8f220781026dd327f40da53eb3a424ec23f38785be8fddc8f1856970dc1
4
- data.tar.gz: 5573e60dc8665ab146e0edeb291ebcd3db6b792180e05e24721df9d519038f86
3
+ metadata.gz: 56185cb3b21dcdc594e86e2f90a5700705e308210cf531371d717798ee7762c4
4
+ data.tar.gz: ec39dc47a6b40b875134431205d7d8da54e83aa7a1818c352dcde485e5f31682
5
5
  SHA512:
6
- metadata.gz: 4ecaa0fef7e6d622f18d2dfe53bdddf2c17fa91e1c2796ee7bdddf5044880f742003d8cb6f7bb4007eeab4bd2f0becba6f8f0fb329f58776f807cd200bd4ced9
7
- data.tar.gz: 76af19179f670d7e4b18121f031b77e18c366259526530b6623f988c5b3e2985ca3a993441e6caacfb7cb71da6afb05c99803234aa85045facdb2c8f09b1194b
6
+ metadata.gz: 639891b42099979c7955fa0586bc8e408900c97a3b0f4197704dd0f4e05765679b80ba83926c9b3c4307e8154f830ef90a4793097901007b11710f93010e1c04
7
+ data.tar.gz: 37c2f1076fddfd3c01da39dada2c579f62cda2af50aa1ba0105184c93c9f1442e4ec66d86e154b02d997310ec09d182991e9a054e5e340759bb11eead4d296bb
data/.builders/boot.rb ADDED
@@ -0,0 +1,40 @@
1
+ # Boot Sequence
2
+
3
+ include KLog::Logging
4
+
5
+ CONFIG_KEY = :k_domain
6
+
7
+ log.kv 'working folder', Dir.pwd
8
+
9
+ Handlebars::Helpers.configure do |config|
10
+ config_file = File.join(Gem.loaded_specs['handlebars-helpers'].full_gem_path, '.handlebars_helpers.json')
11
+ config.helper_config_file = config_file
12
+
13
+ string_config_file = File.join(Gem.loaded_specs['handlebars-helpers'].full_gem_path, '.handlebars_string_formatters.json')
14
+ config.string_formatter_config_file = string_config_file
15
+ end
16
+
17
+ def builder
18
+ @builder ||= KBuilder::BaseBuilder.init(KConfig.configuration(CONFIG_KEY))
19
+ end
20
+
21
+ KConfig.configure(CONFIG_KEY) do |config|
22
+ global_template = File.expand_path('~/dev/kgems/k_templates/templates')
23
+ config.target_folders.add(:app, File.expand_path('../', Dir.pwd))
24
+ config.target_folders.add(:lib_config, :app, 'lib/k_domain/config')
25
+ config.template_folders.add(:global_template, global_template)
26
+ config.template_folders.add(:app_template, File.expand_path('.templates', Dir.pwd))
27
+ end
28
+
29
+ KConfig.configuration(CONFIG_KEY).debug
30
+
31
+ area = KManager.add_area(CONFIG_KEY)
32
+ resource_manager = area.resource_manager
33
+ resource_manager.add_resource('https://raw.githubusercontent.com/klueless-io/k_playground/main/ruby/components/configuration/.builders/configuration_director.rb', content_type: :ruby)
34
+ resource_manager
35
+ .fileset
36
+ .glob('*.rb', exclude: ['boot.rb'])
37
+ .glob('generators/**/*.rb')
38
+ resource_manager.add_resources
39
+
40
+ KManager.boot
@@ -0,0 +1,22 @@
1
+ KManager.action do
2
+ def on_action
3
+ puts '-' * 70
4
+ builder.cd(:lib_config)
5
+ director = ConfigurationDirector
6
+ .init(builder, on_exist: :compare)
7
+ .style(:single)
8
+ .name('Domain Configuration')
9
+ .main_namespace('KDomain', 'Config')
10
+ .add_config_key(:default_main_key, "nil")
11
+ .add_config_key(:default_traits, "%i[trait1 trait2 trait3]")
12
+ .add_config_key(:fallback_keys, "%i[]")
13
+ .add_config_key(:entities, "[]")
14
+ # .logit
15
+
16
+ # dom = director.dom
17
+ # data = director.data
18
+
19
+ director.add_config
20
+ # director.add_configuration
21
+ end
22
+ end
data/.builders/run.rb ADDED
@@ -0,0 +1,16 @@
1
+ # Run
2
+
3
+ KManager.action do
4
+ def on_action
5
+ end
6
+ end
7
+
8
+ KManager.opts.app_name = 'KDomain Generator'
9
+ KManager.opts.sleep = 5
10
+ KManager.opts.reboot_on_kill = 0
11
+ KManager.opts.reboot_sleep = 4
12
+ KManager.opts.exception_style = :short
13
+ KManager.opts.show.time_taken = true
14
+ KManager.opts.show.finished = true
15
+ KManager.opts.show.finished_message = 'FINISHED :)'
16
+
@@ -25,7 +25,9 @@ jobs:
25
25
  run: |
26
26
  gem install bundler -v 2.2.5
27
27
  bundle install
28
- - name: Run tests
29
- run: bundle exec rspec
30
28
  - name: Run rubocop
31
- run: bundle exec rubocop
29
+ run: |
30
+ bundle exec rubocop -v
31
+ bundle exec rubocop
32
+ - name: Run tests
33
+ run: bundle exec rspec --tag ~skip_on_gha
data/.gitignore CHANGED
@@ -23,6 +23,7 @@ k_domain.yml
23
23
  /doc/
24
24
  /pkg/
25
25
  /spec/reports/
26
+ /spec/example_domain/advanced/
26
27
  /tmp/
27
28
  !/tmp/.keep
28
29
  *.bundle
@@ -30,6 +31,7 @@ k_domain.yml
30
31
  *.o
31
32
  *.a
32
33
  mkmf.log
34
+ .vscode
33
35
 
34
36
  # Ruby Version
35
37
  .ruby-version
data/.rubocop.yml CHANGED
@@ -1,16 +1,16 @@
1
1
  # require: rubocop-rake
2
2
  AllCops:
3
- TargetRubyVersion: 2.5
3
+ TargetRubyVersion: 2.7
4
4
  DisplayCopNames: true
5
5
  ExtraDetails: true
6
6
  NewCops: enable
7
7
  Exclude:
8
8
  - "_/**/*"
9
- - "spec/sample_input/**/*"
10
- - "spec/sample_output/**/*"
9
+ - "spec/example_domain/**/*"
11
10
  - "templates/**/*"
12
11
  - "lib/k_domain/schemas/domain/old/**/*"
13
12
  - "spec/k_domain/ruby_loader/**/*"
13
+ - "hooks/**/*"
14
14
 
15
15
  Metrics/PerceivedComplexity:
16
16
  Exclude:
@@ -69,8 +69,6 @@ Metrics/MethodLength:
69
69
 
70
70
  Layout/LineLength:
71
71
  Max: 200
72
- # Ignores annotate output
73
- IgnoredPatterns: ['\A# \*\*']
74
72
  IgnoreCopDirectives: true
75
73
  Exclude:
76
74
  - "lib/k_domain/domain_model/transform_steps/*.rb"
@@ -117,6 +115,12 @@ Style/FormatStringToken:
117
115
  Style/Documentation:
118
116
  Enabled: false
119
117
 
118
+ Style/OpenStructUse:
119
+ Enabled: false
120
+
120
121
  Layout/SpaceBeforeComma:
121
122
  Enabled: false
123
+
124
+ Gemspec/RequireMFA:
125
+ Enabled: false
122
126
  # My Preferences - End
data/Gemfile CHANGED
@@ -25,7 +25,7 @@ group :development, :test do
25
25
  end
26
26
 
27
27
  # If local dependency
28
- if ENV['KLUE_LOCAL_GEMS']&.to_s&.downcase == 'true'
28
+ if ENV.fetch('KLUE_LOCAL_GEMS', 'false').downcase == 'true'
29
29
  group :development, :test do
30
30
  puts 'Using Local GEMs'
31
31
  gem 'k_log' , path: '../k_log'
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/k_domain.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
  require_relative 'lib/k_domain/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.required_ruby_version = '>= 2.5'
6
+ spec.required_ruby_version = '>= 2.7'
7
7
  spec.name = 'k_domain'
8
8
  spec.version = KDomain::VERSION
9
9
  spec.authors = ['David Cruwys']
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './config'
4
+ require_relative './configuration'
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Usage: include KDomain::Config::
4
+
5
+ module KDomain
6
+ module Config
7
+ def configuration
8
+ @configuration ||= KDomain::Config::Configuration.new
9
+ end
10
+
11
+ def reset
12
+ @configuration = KDomain::Config::Configuration.new
13
+ end
14
+
15
+ def configure
16
+ yield(configuration)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module Config
5
+ # Configuration object for Domain Configuration
6
+ class Configuration
7
+ include KLog::Logging
8
+
9
+ ConfigModel = Struct.new(:name, :main_key, :traits)
10
+
11
+ attr_accessor :default_main_key
12
+ attr_accessor :default_traits
13
+ attr_accessor :fallback_keys
14
+ attr_accessor :models
15
+
16
+ def initialize
17
+ @default_main_key = nil
18
+ @default_traits = %i[trait1 trait2 trait3]
19
+ @fallback_keys = %i[]
20
+ @models = []
21
+ end
22
+
23
+ def model(name, main_key: nil, traits: nil)
24
+ @models << new_config_model(
25
+ name,
26
+ main_key: main_key || default_main_key,
27
+ traits: traits || default_traits
28
+ )
29
+ end
30
+
31
+ def find_model(table_name)
32
+ @find_model ||= Hash.new do |h, key|
33
+ h[key] = begin
34
+ entity = models.find { |e| e.name == key }
35
+ entity ||= new_config_model(key)
36
+ entity
37
+ end
38
+ end
39
+
40
+ @find_model[table_name]
41
+ end
42
+
43
+ def fallback_key(columns)
44
+ column_names = columns.each_with_object({}) do |column, hash|
45
+ hash[column.name.to_sym] = column.name.to_sym
46
+ end
47
+
48
+ fallback_keys.find { |key| column_names.key?(key) }
49
+ end
50
+
51
+ def debug(heading: 'Domain configuration')
52
+ log.structure(to_h, title: heading) # , line_width: 150, formatter: formatter)
53
+ ''
54
+ end
55
+
56
+ def to_h
57
+ {
58
+ default_main_key: default_main_key,
59
+ default_traits: default_traits,
60
+ fallback_keys: fallback_keys,
61
+ models: models.map(&:to_h)
62
+ }
63
+ end
64
+
65
+ private
66
+
67
+ def new_config_model(name, main_key: nil, traits: nil)
68
+ ConfigModel.new(
69
+ name,
70
+ main_key || default_main_key,
71
+ traits || default_traits
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Loads the db schema object and works through a series of enrichment steps to
4
+ # that builds the domain modal
5
+
6
+ module KDomain
7
+ module DomainModel
8
+ class BuildRichModels
9
+ include KLog::Logging
10
+
11
+ attr_reader :db_schema
12
+ attr_reader :target_step_file
13
+ attr_reader :query
14
+
15
+ def initialize(domain_model: , target_folder:)
16
+ @domain_model = domain_model
17
+ @target_folder = target_folder
18
+ @query = KDomain::Queries::DomainModelQuery.new(domain_model)
19
+ end
20
+
21
+ def call
22
+ FileUtils.mkdir_p(target_folder)
23
+
24
+ export_domain_models(query.all.take(3))
25
+ end
26
+
27
+ def export_domain_models(models)
28
+ models.each do |model|
29
+ json = JSON.pretty_generate(build_rich_model(model))
30
+ target_file = File.join(target_folder, model.name + '.json')
31
+ File.write(target_file, json)
32
+ end
33
+ end
34
+
35
+ def build_rich_model(model)
36
+ {
37
+ name: model.name,
38
+ name_plural: model.name_plural,
39
+ table_name: model.table_name,
40
+ type: model.type,
41
+ pk: model.pk.to_h,
42
+ file: model.file,
43
+ exist: model.ruby?,
44
+ main_key: model.main_key,
45
+ traits: model.traits,
46
+ columns: {
47
+ all: model.columns.map(&:to_h),
48
+ data: model.columns_data.map(&:to_h),
49
+ primary: model.columns_primary.map(&:to_h),
50
+ foreign_key: model.columns_foreign_key.map(&:to_h),
51
+ foreign_type: model.columns_foreign_type.map(&:to_h),
52
+ timestamp: model.columns_timestamp.map(&:to_h),
53
+ deleted_at: model.columns_deleted_at.map(&:to_h),
54
+ virtual: model.columns_virtual.map(&:to_h),
55
+ data_foreign: model.columns_data_foreign.map(&:to_h),
56
+ data_primary: model.columns_data_primary.map(&:to_h),
57
+ data_virtual: model.columns_data_virtual.map(&:to_h),
58
+ data_foreign_virtual: model.columns_data_foreign_virtual.map(&:to_h)
59
+ }
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -22,7 +22,11 @@ module KDomain
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(@raw_data)
25
+ # This line is slow on big datasets
26
+ @data = KDomain::Schemas::MainDataset.new(@raw_data)
27
+
28
+ # This line is also slow on big datasets
29
+ enrichment
26
30
  end
27
31
 
28
32
  def to_h
@@ -30,6 +34,45 @@ module KDomain
30
34
 
31
35
  @raw_data
32
36
  end
37
+
38
+ private
39
+
40
+ def enrichment
41
+ attach_rails_model_to_domain_model
42
+ end
43
+
44
+ def attach_rails_model_to_domain_model
45
+ @data.domain.models.each do |domain_model|
46
+ domain_model.rails_model = @data.rails_structure.find_model(domain_model.name)
47
+
48
+ if domain_model.rails_model
49
+ attach_column_relations(domain_model)
50
+ else
51
+ log.error("Rails Model not found for #{domain_model.name}") unless domain_model.rails_model
52
+ end
53
+ end
54
+ end
55
+
56
+ def attach_column_relations(domain_model)
57
+ domain_model.columns.each do |column|
58
+ column.relationships = []
59
+ add_column_relations(domain_model.rails_model, column, :belongs_to)
60
+ add_column_relations(domain_model.rails_model, column, :has_one)
61
+ add_column_relations(domain_model.rails_model, column, :has_many)
62
+ add_column_relations(domain_model.rails_model, column, :has_and_belongs_to_many)
63
+ end
64
+ end
65
+
66
+ def add_column_relations(rails_model, column, relation_type)
67
+ relations = rails_model.behaviours.send(relation_type)
68
+
69
+ return if relations.nil?
70
+
71
+ relations = relations.map { |relation| { relation_type: relation_type }.merge(relation.to_h) }
72
+ relations.select { |relation| column[:name] == relation.dig(:opts, :foreign_key) }.each do |relation|
73
+ column.relationships << KDomain::Schemas::Domain::Model::Relationship.new(relation)
74
+ end
75
+ end
33
76
  end
34
77
  end
35
78
  end
@@ -11,24 +11,36 @@ module KDomain
11
11
  attr_reader :db_schema
12
12
  attr_reader :target_step_file
13
13
  attr_reader :target_file
14
- attr_reader :erd_path
14
+ attr_reader :model_path
15
+ attr_reader :controller_path
16
+ attr_reader :route_path
17
+ attr_reader :model_shim_loader
18
+ attr_reader :controller_shim_loader
15
19
 
16
- def initialize(db_schema: , target_file: , target_step_file: , erd_path:)
17
- @db_schema = db_schema
18
- @target_step_file = target_step_file
19
- @target_file = target_file
20
- @erd_path = erd_path
20
+ # rubocop:disable Metrics/ParameterLists
21
+ def initialize(db_schema: , target_file: , target_step_file: , model_path:, route_path:, controller_path:, model_shim_loader: nil, controller_shim_loader: nil)
22
+ @db_schema = db_schema
23
+ @target_step_file = target_step_file
24
+ @target_file = target_file
25
+ @model_path = model_path
26
+ @controller_path = controller_path
27
+ @route_path = route_path
28
+ @model_shim_loader = model_shim_loader
29
+ @controller_shim_loader = controller_shim_loader
21
30
  end
31
+ # rubocop:enable Metrics/ParameterLists
22
32
 
23
33
  # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
24
34
  def call
25
35
  valid = true
26
- valid &&= Step1AttachDbSchema.run(domain_data, db_schema: db_schema, step_file: step_file('1-attach-db-schema'))
27
- valid &&= Step2AttachModels.run(domain_data, erd_path: erd_path, step_file: step_file('2-attach-model'))
28
- valid &&= Step3AttachColumns.run(domain_data, step_file: step_file('3-attach-columns'))
29
- valid &&= Step4RailsResourceModels.run(domain_data, erd_path: erd_path, step_file: step_file('4-rails-resource-models'))
30
- valid &&= Step5RailsModels.run(domain_data, erd_path: erd_path, step_file: step_file('5-rails-models'))
31
- valid &&= Step6AttachDictionary.run(domain_data, erd_path: erd_path, step_file: step_file('6-attach-dictionary'))
36
+ valid &&= Step1DbSchema.run(domain_data, db_schema: db_schema, step_file: step_file('01-db-schema'))
37
+ valid &&= Step2DomainModels.run(domain_data, model_path: model_path, step_file: step_file('02-domain-model'))
38
+ valid &&= Step4RailsResourceModels.run(domain_data, model_path: model_path, step_file: step_file('04-rails-resource-models'))
39
+ valid &&= Step5RailsResourceRoutes.run(domain_data, route_path: route_path, controller_path: controller_path, step_file: step_file('05-rails-resource-routes'))
40
+ valid &&= Step6RailsStructureModels.run(domain_data, model_path: model_path, step_file: step_file('06-rails-structure-models'), shim_loader: model_shim_loader)
41
+ valid &&= Step7RailsStructureControllers.run(domain_data, controller_path: controller_path, step_file: step_file('07-rails-structure-controllers'), shim_loader: controller_shim_loader)
42
+ valid &&= Step8DomainColumns.run(domain_data, step_file: step_file('08-domain-columns'))
43
+ valid &&= Step20Dictionary.run(domain_data, step_file: step_file('20-dictionary'))
32
44
 
33
45
  raise 'DomainModal transform failed' unless valid
34
46
 
@@ -39,7 +51,7 @@ module KDomain
39
51
  # rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
40
52
 
41
53
  def step_file(step_name)
42
- target_step_file % { step: step_name }
54
+ format(target_step_file, step: step_name)
43
55
  end
44
56
 
45
57
  def write
@@ -52,11 +64,11 @@ module KDomain
52
64
  # The initial domain model structure is created here, but populated during the workflows.
53
65
  @domain_data ||= {
54
66
  domain: {
55
- models: [],
67
+ models: []
56
68
  },
57
69
  rails_resource: {
58
70
  models: [],
59
- controllers: []
71
+ routes: []
60
72
  },
61
73
  rails_structure: {
62
74
  models: [],
@@ -69,6 +81,7 @@ module KDomain
69
81
  tables: [],
70
82
  indexes: [],
71
83
  foreign_keys: [],
84
+ views: [],
72
85
  meta: {}
73
86
  },
74
87
  investigate: {
@@ -76,7 +89,6 @@ module KDomain
76
89
  }
77
90
  }
78
91
  end
79
-
80
92
  # rubocop:enable Metrics/MethodLength
81
93
  end
82
94
  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 './step1_attach_db_schema'
6
- require_relative './step2_attach_models'
7
- require_relative './step3_attach_columns'
5
+ require_relative './step1_db_schema'
6
+ require_relative './step2_domain_models'
8
7
  require_relative './step4_rails_resource_models'
9
- require_relative './step5_rails_models'
10
- require_relative './step6_attach_dictionary'
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'
@@ -33,6 +33,10 @@ module KDomain
33
33
  @valid = false
34
34
  end
35
35
 
36
+ def warning(message)
37
+ log.warn message
38
+ end
39
+
36
40
  def write(file)
37
41
  FileUtils.mkdir_p(File.dirname(file))
38
42
  File.write(file, JSON.pretty_generate(domain_data))
@@ -64,6 +68,14 @@ module KDomain
64
68
  rails_resource[:models] = value
65
69
  end
66
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
+
67
79
  def rails_resource_controllers
68
80
  rails_resource[:controllers]
69
81
  end
@@ -79,6 +91,10 @@ module KDomain
79
91
  rails_structure[:models]
80
92
  end
81
93
 
94
+ def find_rails_structure_models(model_name)
95
+ rails_structure_models.find { |model| model[:model_name] == model_name }
96
+ end
97
+
82
98
  def rails_structure_models=(value)
83
99
  rails_structure[:models] = value
84
100
  end
@@ -87,6 +103,10 @@ module KDomain
87
103
  rails_structure[:controllers]
88
104
  end
89
105
 
106
+ def rails_structure_controllers=(value)
107
+ rails_structure[:controllers] = value
108
+ end
109
+
90
110
  # Database Accessor/Helpers
91
111
  def database=(value)
92
112
  domain_data[:database] = value
@@ -2,12 +2,13 @@
2
2
 
3
3
  module KDomain
4
4
  module DomainModel
5
- class Step1AttachDbSchema < KDomain::DomainModel::Step
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] # .take(10) # .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?
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Attach data dictionary
4
- class Step6AttachDictionary < KDomain::DomainModel::Step
3
+ # data dictionary
4
+ class Step20Dictionary < KDomain::DomainModel::Step
5
5
  attr_reader :dictionary
6
6
 
7
7
  def call
@@ -27,10 +27,10 @@ class Step6AttachDictionary < KDomain::DomainModel::Step
27
27
  entry[:model_count] = entry[:model_count] + 1
28
28
 
29
29
  unless entry[:types].include?(column_type)
30
- investigate(step: :step5_attach_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}")
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
34
 
35
35
  entry[:types] << column_type
36
36
  entry[:type_count] = entry[:type_count] + 1