k_domain 0.0.11 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -1
  3. data/Gemfile +1 -1
  4. data/Rakefile +3 -1
  5. data/STORIES.md +35 -6
  6. data/k_domain.gemspec +1 -0
  7. data/lib/k_domain/domain_model/load.rb +8 -2
  8. data/lib/k_domain/domain_model/transform.rb +24 -49
  9. data/lib/k_domain/domain_model/transform_steps/_.rb +3 -3
  10. data/lib/k_domain/domain_model/transform_steps/step.rb +36 -11
  11. data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +1 -1
  12. data/lib/k_domain/domain_model/transform_steps/{step8_locate_rails_models.rb → step4_rails_resource_models.rb} +5 -3
  13. data/lib/k_domain/domain_model/transform_steps/step5_rails_models.rb +71 -0
  14. data/lib/k_domain/domain_model/transform_steps/{step5_attach_dictionary.rb → step6_attach_dictionary.rb} +9 -3
  15. data/lib/k_domain/rails_code_extractor/extract_model.rb +58 -0
  16. data/lib/k_domain/rails_code_extractor/shim_loader.rb +29 -0
  17. data/lib/k_domain/raw_db_schema/load.rb +8 -2
  18. data/lib/k_domain/raw_db_schema/transform.rb +5 -6
  19. data/lib/k_domain/schemas/_.rb +16 -0
  20. data/lib/k_domain/schemas/database/_.rb +0 -7
  21. data/lib/k_domain/schemas/database/index.rb +1 -1
  22. data/lib/k_domain/schemas/database/schema.rb +15 -2
  23. data/lib/k_domain/schemas/database/table.rb +19 -8
  24. data/lib/k_domain/schemas/dictionary.rb +19 -0
  25. data/lib/k_domain/schemas/domain/_.rb +0 -3
  26. data/lib/k_domain/schemas/domain/domain.rb +1 -2
  27. data/lib/k_domain/schemas/domain/erd_file.rb +2 -0
  28. data/lib/k_domain/schemas/domain_model.rb +15 -0
  29. data/lib/k_domain/schemas/{domain/investigate.rb → investigate.rb} +1 -1
  30. data/lib/k_domain/schemas/rails_resource.rb +16 -0
  31. data/lib/k_domain/schemas/rails_structure.rb +92 -0
  32. data/lib/k_domain/version.rb +1 -1
  33. data/lib/k_domain.rb +13 -3
  34. data/templates/active_record_shims.rb +368 -0
  35. data/templates/fake_module_shims.rb +42 -0
  36. data/{lib/k_domain/raw_db_schema/template.rb → templates/load_schema.rb} +4 -4
  37. metadata +16 -12
  38. data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +0 -454
  39. data/lib/k_domain/schemas/database/column.rb +0 -16
  40. data/lib/k_domain/schemas/database/database.rb +0 -11
  41. data/lib/k_domain/schemas/database/unique_key.rb +0 -14
  42. data/lib/k_domain/schemas/domain/dictionary.rb +0 -17
  43. data/lib/k_domain/schemas/domain/schema.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0641cc1145379d1ba83cad6765dbf85bd50bb40ce69105a977eb9ced5326046
4
- data.tar.gz: ac7f352029bcea76171cf87ccf56212e11b3173256519394cc2802e21fd47981
3
+ metadata.gz: de5fc8f220781026dd327f40da53eb3a424ec23f38785be8fddc8f1856970dc1
4
+ data.tar.gz: 5573e60dc8665ab146e0edeb291ebcd3db6b792180e05e24721df9d519038f86
5
5
  SHA512:
6
- metadata.gz: d2b9ce5ced5669eb620f9c3735fbbaf06e12b6c9f9e5eb6507d3526aefcfe5eb624ce5361a14bc39c2c8449eaa31b3e0caa082b6fca07fba23b166be550fc023
7
- data.tar.gz: a22f3ee11a7b7ef9a9793d01237c5e14f0ed89972d91ede7ed87c29c260b57fca1445ea1bac92830d2299767335e49dc41f2f7b6917a7e08ffb5f8383bbf2ed4
6
+ metadata.gz: 4ecaa0fef7e6d622f18d2dfe53bdddf2c17fa91e1c2796ee7bdddf5044880f742003d8cb6f7bb4007eeab4bd2f0becba6f8f0fb329f58776f807cd200bd4ced9
7
+ data.tar.gz: 76af19179f670d7e4b18121f031b77e18c366259526530b6623f988c5b3e2985ca3a993441e6caacfb7cb71da6afb05c99803234aa85045facdb2c8f09b1194b
data/.rubocop.yml CHANGED
@@ -8,7 +8,9 @@ AllCops:
8
8
  - "_/**/*"
9
9
  - "spec/sample_input/**/*"
10
10
  - "spec/sample_output/**/*"
11
- - "lib/k_domain/raw_db_schema/template.rb"
11
+ - "templates/**/*"
12
+ - "lib/k_domain/schemas/domain/old/**/*"
13
+ - "spec/k_domain/ruby_loader/**/*"
12
14
 
13
15
  Metrics/PerceivedComplexity:
14
16
  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/Rakefile CHANGED
@@ -26,7 +26,9 @@ task :publish do
26
26
  system 'gem build'
27
27
  system "gem push #{GEM_NAME}-#{KDomain::VERSION}.gem"
28
28
  end
29
-
29
+ task :build do
30
+ system 'gem build'
31
+ end
30
32
  desc 'Remove old *.gem files'
31
33
  task :clean do
32
34
  system 'rm *.gem'
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 next on list
52
+ ### Tasks - completed
24
53
 
25
54
  Refactor / Simply
26
55
 
27
- - Replace complex objects an with structs for ancillary data structures such as investigate
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
@@ -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']
@@ -20,9 +20,15 @@ module KDomain
20
20
 
21
21
  def call
22
22
  json = File.read(source_file)
23
- data = KUtil.data.json_parse(json, as: :hash_symbolized)
23
+ @raw_data = KUtil.data.json_parse(json, as: :hash_symbolized)
24
24
 
25
- @data = KDomain::DomainModel::Schema.new(data)
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,21 +13,22 @@ 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
- valid &&= step1
26
- valid &&= step2
27
- valid &&= step3
28
- valid &&= step4
29
- valid &&= step5
30
- valid &&= step8 # NOT SURE WHERE THIS BELONGS
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'))
31
32
 
32
33
  raise 'DomainModal transform failed' unless valid
33
34
 
@@ -35,62 +36,34 @@ module KDomain
35
36
 
36
37
  nil
37
38
  end
39
+ # rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
38
40
 
39
- def step1
40
- Step1AttachDbSchema.run(domain_data, db_schema: db_schema)
41
- write(step: '1-attach-db-schema')
41
+ def step_file(step_name)
42
+ target_step_file % { step: step_name }
42
43
  end
43
44
 
44
- def step2
45
- Step2AttachModels.run(domain_data, erd_path: erd_path)
46
- write(step: '2-attach-model')
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))
45
+ def write
46
+ FileUtils.mkdir_p(File.dirname(target_file))
47
+ File.write(target_file, JSON.pretty_generate(domain_data))
77
48
  end
78
49
 
50
+ # rubocop:disable Metrics/MethodLength
79
51
  def domain_data
80
52
  # The initial domain model structure is created here, but populated during the workflows.
81
53
  @domain_data ||= {
82
54
  domain: {
83
55
  models: [],
84
- erd_files: [],
85
- dictionary: []
86
56
  },
87
- rails: {
57
+ rails_resource: {
88
58
  models: [],
89
- controllers: [],
59
+ controllers: []
90
60
  },
91
- rails_files: {
61
+ rails_structure: {
92
62
  models: [],
93
- controllers: [],
63
+ controllers: []
64
+ },
65
+ dictionary: {
66
+ items: []
94
67
  },
95
68
  database: {
96
69
  tables: [],
@@ -103,6 +76,8 @@ module KDomain
103
76
  }
104
77
  }
105
78
  end
79
+
80
+ # rubocop:enable Metrics/MethodLength
106
81
  end
107
82
  end
108
83
  end
@@ -5,6 +5,6 @@ require_relative './step'
5
5
  require_relative './step1_attach_db_schema'
6
6
  require_relative './step2_attach_models'
7
7
  require_relative './step3_attach_columns'
8
- require_relative './step4_attach_erd_files'
9
- require_relative './step5_attach_dictionary'
10
- require_relative './step8_locate_rails_models'
8
+ require_relative './step4_rails_resource_models'
9
+ require_relative './step5_rails_models'
10
+ require_relative './step6_attach_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,11 @@ module KDomain
32
33
  @valid = false
33
34
  end
34
35
 
36
+ def write(file)
37
+ FileUtils.mkdir_p(File.dirname(file))
38
+ File.write(file, JSON.pretty_generate(domain_data))
39
+ end
40
+
35
41
  # Domain Model Accessor/Helpers
36
42
  def domain
37
43
  guard('domain is missing') if domain_data[:domain].nil?
@@ -43,23 +49,42 @@ module KDomain
43
49
  domain[:models]
44
50
  end
45
51
 
46
- # Rails File Accessor/Helpers
47
- def rails_files
48
- guard('rails_files is missing') if domain_data[:rails_files].nil?
52
+ # Rails Resource File Accessor/Helpers
53
+ def rails_resource
54
+ guard('rails_resource is missing') if domain_data[:rails_resource].nil?
55
+
56
+ domain_data[:rails_resource]
57
+ end
58
+
59
+ def rails_resource_models
60
+ rails_resource[:models]
61
+ end
62
+
63
+ def rails_resource_models=(value)
64
+ rails_resource[:models] = value
65
+ end
66
+
67
+ def rails_resource_controllers
68
+ rails_resource[:controllers]
69
+ end
70
+
71
+ # Rails Structure File Accessor/Helpers
72
+ def rails_structure
73
+ guard('rails_structure is missing') if domain_data[:rails_structure].nil?
49
74
 
50
- domain_data[:rails_files]
75
+ domain_data[:rails_structure]
51
76
  end
52
77
 
53
- def rails_files_models
54
- rails_files[:models]
78
+ def rails_structure_models
79
+ rails_structure[:models]
55
80
  end
56
81
 
57
- def rails_files_models=(value)
58
- rails_files[:models] = value
82
+ def rails_structure_models=(value)
83
+ rails_structure[:models] = value
59
84
  end
60
85
 
61
- def rails_files_controllers
62
- rails_files[:controllers]
86
+ def rails_structure_controllers
87
+ rails_structure[:controllers]
63
88
  end
64
89
 
65
90
  # Database Accessor/Helpers
@@ -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][:database][:extensions].nil?
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
@@ -1,18 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Locate rails model files
4
- class Step8LocateRailsModels < KDomain::DomainModel::Step
4
+ class Step4RailsResourceModels < KDomain::DomainModel::Step
5
5
  attr_accessor :ruby_code
6
6
 
7
7
  def call
8
8
  raise 'ERD path not supplied' if opts[:erd_path].nil?
9
9
 
10
- self.rails_files_models = domain_models.map { |model| locate_rails_model(model[:name], model[:table_name]) }
10
+ self.rails_resource_models = domain_models.map do |model|
11
+ locate_rails_model(model[:name], model[:table_name])
12
+ end
11
13
  end
12
14
 
13
15
  private
14
16
 
15
- def locate_rails_model(table_name, model_name)
17
+ def locate_rails_model(model_name, table_name)
16
18
  file_normal = File.join(opts[:erd_path], "#{model_name}.rb")
17
19
  file_custom = File.join(opts[:erd_path], "#{table_name}.rb")
18
20
  file_exist = true
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Locate rails model files
4
+ class Step5RailsModels < KDomain::DomainModel::Step
5
+ def call
6
+ raise 'ERD path not supplied' unless opts[:erd_path]
7
+
8
+ self.rails_structure_models = rails_resource_models.map do |resource|
9
+ process_resource(OpenStruct.new(resource))
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def process_resource(resource)
16
+ @model = {
17
+ model_name: resource.model_name,
18
+ table_name: resource.table_name,
19
+ file: resource.file,
20
+ exist: resource.exist,
21
+ state: resource.state,
22
+ code: resource.exist ? File.read(resource.file) : '',
23
+ behaviours: {},
24
+ functions: {}
25
+ }
26
+
27
+ return @model unless resource.exist
28
+
29
+ @model[:behaviours] = extract_model_behavior(resource.file)
30
+ @model[:functions] = extract_model_functions(resource.file)
31
+
32
+ @model
33
+ end
34
+
35
+ def extract_model_behavior(file)
36
+ extractor.extract(file)
37
+ extractor.model
38
+ end
39
+
40
+ def extract_model_functions(file)
41
+ klass_name = File.basename(file, File.extname(file))
42
+
43
+ klass = case klass_name
44
+ when 'clearbit_quota'
45
+ ClearbitQuota
46
+ when 'account_history_data'
47
+ AccountHistoryData
48
+ else
49
+ Module.const_get(klass_name.classify)
50
+ end
51
+
52
+ class_info = Peeky.api.build_class_info(klass.new)
53
+
54
+ class_info.to_h
55
+ rescue StandardError => e
56
+ log.exception(e)
57
+ end
58
+
59
+ def extractor
60
+ @extractor ||= KDomain::RailsCodeExtractor::ExtractModel.new(shim_loader)
61
+ end
62
+
63
+ def shim_loader
64
+ return opts[:shim_loader] if !opts[:shim_loader].nil? && opts[:shim_loader].is_a?(KDomain::RailsCodeExtractor::ShimLoader)
65
+
66
+ shim_loader = KDomain::RailsCodeExtractor::ShimLoader.new
67
+ shim_loader.register(:fake_module , KDomain::Gem.resource('templates/fake_module_shims.rb'))
68
+ shim_loader.register(:active_record, KDomain::Gem.resource('templates/active_record_shims.rb'))
69
+ shim_loader
70
+ end
71
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Attach data dictionary
4
- class Step5AttachDictionary < KDomain::DomainModel::Step
4
+ class Step6AttachDictionary < KDomain::DomainModel::Step
5
5
  attr_reader :dictionary
6
6
 
7
7
  def call
@@ -13,7 +13,9 @@ class Step5AttachDictionary < KDomain::DomainModel::Step
13
13
  end
14
14
  end
15
15
 
16
- domain[:dictionary] = dictionary.values
16
+ domain_data[:dictionary] = {
17
+ items: dictionary.values
18
+ }
17
19
  end
18
20
 
19
21
  private
@@ -25,7 +27,11 @@ 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
- log.warn("#{model_name} has a type mismatch for column name: #{column_name}")
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}")
34
+
29
35
  entry[:types] << column_type
30
36
  entry[:type_count] = entry[:type_count] + 1
31
37
  end
@@ -0,0 +1,58 @@
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 :shims_loaded
10
+ attr_reader :models
11
+ attr_reader :model
12
+
13
+ def initialize(load_shim)
14
+ @load_shim = load_shim
15
+ @shims_loaded = false
16
+ @models = []
17
+ end
18
+
19
+ def extract(file)
20
+ load_shims unless shims_loaded
21
+
22
+ ActiveRecord.current_class = nil
23
+
24
+ load_retry(file, 10)
25
+ rescue StandardError => e
26
+ log.exception(e)
27
+ end
28
+
29
+ private
30
+
31
+ def load_shims
32
+ @load_shim.call
33
+ @shims_loaded = true
34
+ end
35
+
36
+ # rubocop:disable Security/Eval,Style/EvalWithLocation,Style/DocumentDynamicEvalDefinition,Metrics/AbcSize
37
+ def load_retry(file, times)
38
+ return if times.negative?
39
+
40
+ load(file)
41
+
42
+ @model = ActiveRecord.current_class
43
+ @models << @model
44
+
45
+ # get_method_info(File.base_name(file))
46
+ rescue StandardError => e
47
+ puts e.message
48
+ if e.is_a?(NameError)
49
+ log.kv('add module', e.name)
50
+ eval("module #{e.name}; end")
51
+ return load_retry(path, times - 1)
52
+ end
53
+ log.exception(e)
54
+ end
55
+ # rubocop:enable Security/Eval,Style/EvalWithLocation,Style/DocumentDynamicEvalDefinition,Metrics/AbcSize
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,29 @@
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 ShimLoader
12
+ include KLog::Logging
13
+
14
+ attr_reader :shim_files
15
+
16
+ def initialize
17
+ @shim_files = []
18
+ end
19
+
20
+ def call
21
+ shim_files.select { |sf| sf[:exist] }.each { |sf| require sf[:file] }
22
+ end
23
+
24
+ def register(name, file)
25
+ @shim_files << { name: name, file: file, exist: File.exist?(file) }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -20,9 +20,15 @@ module KDomain
20
20
 
21
21
  def call
22
22
  json = File.read(source_file)
23
- data = KUtil.data.json_parse(json, as: :hash_symbolized)
23
+ @raw_data = KUtil.data.json_parse(json, as: :hash_symbolized)
24
24
 
25
- @data = KDomain::Database::Schema.new(data)
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
@@ -16,7 +16,7 @@ module KDomain
16
16
 
17
17
  def initialize(source_file)
18
18
  @source_file = source_file
19
- @template_file = 'lib/k_domain/raw_db_schema/template.rb'
19
+ @template_file = KDomain::Gem.resource('templates/load_schema.rb')
20
20
  end
21
21
 
22
22
  def call
@@ -24,7 +24,6 @@ module KDomain
24
24
  # log.kv 'template_file', template_file
25
25
  # log.kv 'source_file?', File.exist?(source_file)
26
26
  # log.kv 'template_file?', File.exist?(template_file)
27
-
28
27
  log.error "Template not found: #{template_file}" unless File.exist?(template_file)
29
28
 
30
29
  content = File.read(source_file)
@@ -69,13 +68,13 @@ module KDomain
69
68
  return
70
69
  end
71
70
 
72
- eval(schema_loader)#, __FILE__, __LINE__)
71
+ eval(schema_loader) # , __FILE__, __LINE__)
73
72
 
74
73
  loader = LoadSchema.new
75
74
  loader.load_schema
76
- return loader.schema
77
- rescue => ex
78
- log.exception(ex)
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,16 @@
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 'rails_structure'
11
+ require_relative 'investigate'
12
+ require_relative 'database/_'
13
+ require_relative 'dictionary'
14
+ require_relative 'domain/_'
15
+
16
+ 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'
@@ -8,7 +8,7 @@ module KDomain
8
8
  attribute :using , Types::Nominal::String
9
9
  attribute :order? , Types::Nominal::Hash
10
10
  attribute :where? , Types::Nominal::Any.optional.default(nil)
11
- attribute :unique? , Types::Nominal::Any.optional.default(nil)
11
+ attribute :unique? , Types::Nominal::Any.optional.default(nil)
12
12
  end
13
13
  end
14
14
  end