k_domain 0.0.23 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/boot.rb +40 -0
- data/.builders/generators/configuration_generator.rb +22 -0
- data/.builders/run.rb +16 -0
- data/.github/workflows/main.yml +5 -3
- data/.gitignore +1 -0
- data/.rubocop.yml +8 -3
- data/Gemfile +2 -2
- data/k_domain.gemspec +1 -1
- data/lib/k_domain/config/_.rb +4 -0
- data/lib/k_domain/config/config.rb +19 -0
- data/lib/k_domain/config/configuration.rb +76 -0
- data/lib/k_domain/domain_model/build_rich_models.rb +83 -0
- data/lib/k_domain/domain_model/load.rb +44 -1
- data/lib/k_domain/domain_model/transform.rb +13 -11
- data/lib/k_domain/domain_model/transform_steps/step1_db_schema.rb +1 -1
- data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +1 -1
- data/lib/k_domain/domain_model/transform_steps/step6_rails_structure_models.rb +1 -0
- data/lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb +8 -3
- data/lib/k_domain/domain_model/transform_steps/step8_domain_columns.rb +51 -56
- data/lib/k_domain/queries/_.rb +4 -0
- data/lib/k_domain/queries/base_query.rb +13 -0
- data/lib/k_domain/queries/domain_model_query.rb +88 -0
- data/lib/k_domain/rails_code_extractor/extract_controller.rb +2 -0
- data/lib/k_domain/rails_code_extractor/extract_model.rb +2 -0
- data/lib/k_domain/rails_code_extractor/shim_loader.rb +4 -2
- data/lib/k_domain/raw_db_schema/transform.rb +26 -2
- data/lib/k_domain/schemas/_.rb +3 -1
- data/lib/k_domain/schemas/domain/erd_file.rb +78 -77
- data/lib/k_domain/schemas/domain.rb +79 -38
- data/lib/k_domain/schemas/{domain/_.rb → domain_types.rb} +1 -8
- data/lib/k_domain/schemas/{domain_model.rb → main_dataset.rb} +2 -2
- data/lib/k_domain/schemas/rails_structure.rb +10 -0
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +6 -1
- data/templates/custom/action_controller.rb +0 -29
- data/templates/custom/controller_interceptors.rb +9 -7
- data/templates/custom/model_interceptors.rb +48 -3
- data/templates/rails/active_record.rb +2 -0
- data/templates/sample_config.rb +47 -0
- metadata +17 -10
- data/.builders/config/_.rb +0 -3
- data/.builders/setup.rb +0 -30
- data/templates/old_printspeek_schema copy.rb +0 -231
- data/templates/old_printspeek_schema.rb +0 -233
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2206bc03f809354e7cacb541a081491e1ce06c8eb82eb655cd81fdc7d16a69e7
|
4
|
+
data.tar.gz: 9e5f99803fee97745f11e870b79039510e0b0c733d43191c1cf5557d8e138b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2576e2e9f17587883e1edea8b8b32cbab53530574657511870de4bb679cb0b32822970937efab04ee7ca15a689ec8b3ffaf7856872e96e9696a8775ce00aaf8d
|
7
|
+
data.tar.gz: ecd8d2f12229d9cf422515be37091ee8e13b893712f7ba15e236a515319b31b301fb468ab75e6034233cd028bb0cc0c98e0216d9c12bbae60b4a66f20584e8db
|
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
|
+
|
data/.github/workflows/main.yml
CHANGED
@@ -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:
|
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
data/.rubocop.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# require: rubocop-rake
|
2
2
|
AllCops:
|
3
|
-
TargetRubyVersion: 2.
|
3
|
+
TargetRubyVersion: 2.7
|
4
4
|
DisplayCopNames: true
|
5
5
|
ExtraDetails: true
|
6
6
|
NewCops: enable
|
@@ -10,6 +10,7 @@ AllCops:
|
|
10
10
|
- "templates/**/*"
|
11
11
|
- "lib/k_domain/schemas/domain/old/**/*"
|
12
12
|
- "spec/k_domain/ruby_loader/**/*"
|
13
|
+
- "hooks/**/*"
|
13
14
|
|
14
15
|
Metrics/PerceivedComplexity:
|
15
16
|
Exclude:
|
@@ -68,8 +69,6 @@ Metrics/MethodLength:
|
|
68
69
|
|
69
70
|
Layout/LineLength:
|
70
71
|
Max: 200
|
71
|
-
# Ignores annotate output
|
72
|
-
IgnoredPatterns: ['\A# \*\*']
|
73
72
|
IgnoreCopDirectives: true
|
74
73
|
Exclude:
|
75
74
|
- "lib/k_domain/domain_model/transform_steps/*.rb"
|
@@ -116,6 +115,12 @@ Style/FormatStringToken:
|
|
116
115
|
Style/Documentation:
|
117
116
|
Enabled: false
|
118
117
|
|
118
|
+
Style/OpenStructUse:
|
119
|
+
Enabled: false
|
120
|
+
|
119
121
|
Layout/SpaceBeforeComma:
|
120
122
|
Enabled: false
|
123
|
+
|
124
|
+
Gemspec/RequireMFA:
|
125
|
+
Enabled: false
|
121
126
|
# My Preferences - End
|
data/Gemfile
CHANGED
@@ -16,7 +16,7 @@ group :development, :test do
|
|
16
16
|
gem 'guard-bundler'
|
17
17
|
gem 'guard-rspec'
|
18
18
|
gem 'guard-rubocop'
|
19
|
-
gem 'rake'
|
19
|
+
gem 'rake'
|
20
20
|
gem 'rake-compiler', require: false
|
21
21
|
gem 'rspec', '~> 3.0'
|
22
22
|
gem 'rubocop'
|
@@ -25,7 +25,7 @@ group :development, :test do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# If local dependency
|
28
|
-
if ENV
|
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/k_domain.gemspec
CHANGED
@@ -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,83 @@
|
|
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_folder
|
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
|
+
puts 'export domain models'
|
29
|
+
models.each do |model|
|
30
|
+
# write a single dot to the console in the color red
|
31
|
+
print "\e[31m.\e[0m"
|
32
|
+
|
33
|
+
json = JSON.pretty_generate(build_rich_model(model))
|
34
|
+
target_file = File.join(target_folder, "#{model.name}.json")
|
35
|
+
File.write(target_file, json)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_rich_model(model)
|
40
|
+
{
|
41
|
+
name: model.name,
|
42
|
+
name_plural: model.name_plural,
|
43
|
+
table_name: model.table_name,
|
44
|
+
type: model.type,
|
45
|
+
pk: model.pk.to_h,
|
46
|
+
file: model.file,
|
47
|
+
exist: model.ruby?,
|
48
|
+
create_update_timestamp: model.create_update_timestamp?,
|
49
|
+
main_key: model.main_key,
|
50
|
+
traits: model.traits,
|
51
|
+
column_names: {
|
52
|
+
all: model.columns.map(&:name),
|
53
|
+
data: model.columns_data.map(&:name),
|
54
|
+
primary: model.columns_primary.map(&:name),
|
55
|
+
foreign_key: model.columns_foreign_key.map(&:name),
|
56
|
+
foreign_type: model.columns_foreign_type.map(&:name),
|
57
|
+
timestamp: model.columns_timestamp.map(&:name),
|
58
|
+
deleted_at: model.columns_deleted_at.map(&:name),
|
59
|
+
virtual: model.columns_virtual.map(&:name),
|
60
|
+
data_foreign: model.columns_data_foreign.map(&:name),
|
61
|
+
data_primary: model.columns_data_primary.map(&:name),
|
62
|
+
data_virtual: model.columns_data_virtual.map(&:name),
|
63
|
+
data_foreign_virtual: model.columns_data_foreign_virtual.map(&:name)
|
64
|
+
},
|
65
|
+
columns: {
|
66
|
+
all: model.columns.map(&:to_h),
|
67
|
+
data: model.columns_data.map(&:to_h),
|
68
|
+
primary: model.columns_primary.map(&:to_h),
|
69
|
+
foreign_key: model.columns_foreign_key.map(&:to_h),
|
70
|
+
foreign_type: model.columns_foreign_type.map(&:to_h),
|
71
|
+
timestamp: model.columns_timestamp.map(&:to_h),
|
72
|
+
deleted_at: model.columns_deleted_at.map(&:to_h),
|
73
|
+
virtual: model.columns_virtual.map(&:to_h),
|
74
|
+
data_foreign: model.columns_data_foreign.map(&:to_h),
|
75
|
+
data_primary: model.columns_data_primary.map(&:to_h),
|
76
|
+
data_virtual: model.columns_data_virtual.map(&:to_h),
|
77
|
+
data_foreign_virtual: model.columns_data_foreign_virtual.map(&:to_h)
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
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
|
-
|
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
|
@@ -14,17 +14,19 @@ module KDomain
|
|
14
14
|
attr_reader :model_path
|
15
15
|
attr_reader :controller_path
|
16
16
|
attr_reader :route_path
|
17
|
-
attr_reader :
|
17
|
+
attr_reader :model_shim_loader
|
18
|
+
attr_reader :controller_shim_loader
|
18
19
|
|
19
20
|
# rubocop:disable Metrics/ParameterLists
|
20
|
-
def initialize(db_schema: , target_file: , target_step_file: , model_path:, route_path:, controller_path:,
|
21
|
-
@db_schema
|
22
|
-
@target_step_file
|
23
|
-
@target_file
|
24
|
-
@model_path
|
25
|
-
@controller_path
|
26
|
-
@route_path
|
27
|
-
@
|
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
|
28
30
|
end
|
29
31
|
# rubocop:enable Metrics/ParameterLists
|
30
32
|
|
@@ -35,8 +37,8 @@ module KDomain
|
|
35
37
|
valid &&= Step2DomainModels.run(domain_data, model_path: model_path, step_file: step_file('02-domain-model'))
|
36
38
|
valid &&= Step4RailsResourceModels.run(domain_data, model_path: model_path, step_file: step_file('04-rails-resource-models'))
|
37
39
|
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:
|
39
|
-
valid &&= Step7RailsStructureControllers.run(domain_data, controller_path: controller_path, step_file: step_file('07-rails-structure-controllers'), shim_loader:
|
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)
|
40
42
|
valid &&= Step8DomainColumns.run(domain_data, step_file: step_file('08-domain-columns'))
|
41
43
|
valid &&= Step20Dictionary.run(domain_data, step_file: step_file('20-dictionary'))
|
42
44
|
|
@@ -8,7 +8,7 @@ module KDomain
|
|
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
|
+
database[:tables] = database[:tables] # .take(10) # .slice(156, 1)
|
12
12
|
|
13
13
|
guard('tables are missing') if database[:tables].nil?
|
14
14
|
guard('indexes are missing') if database[:indexes].nil?
|
@@ -18,7 +18,7 @@ class Step2DomainModels < KDomain::DomainModel::Step
|
|
18
18
|
name_plural: table_name, # need to check if this is correct as I know it is wrong for account_history_datum
|
19
19
|
table_name: table_name,
|
20
20
|
pk: primary_key(table),
|
21
|
-
file: nil
|
21
|
+
file: nil # will be set in step8_domain_columns
|
22
22
|
}
|
23
23
|
|
24
24
|
attach_columns(model)
|
@@ -37,6 +37,7 @@ class Step6RailsStructureModels < KDomain::DomainModel::Step
|
|
37
37
|
|
38
38
|
def attach_behavior_and_functions
|
39
39
|
rails_structure_models.select { |model| model[:exist] }.each do |model|
|
40
|
+
# puts "model: #{model[:model_name]}"
|
40
41
|
model[:behaviours] = extract_behavior(model[:file])
|
41
42
|
klass_name = model[:behaviours][:class_name]
|
42
43
|
model[:functions] = extract_functions(klass_name)
|
@@ -58,7 +58,10 @@ class Step7RailsStructureControllers < KDomain::DomainModel::Step
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def attach_behavior_and_functions
|
61
|
+
rails_structure_controllers.sort_by! { |controller| controller[:full_file] }
|
62
|
+
|
61
63
|
rails_structure_controllers.select { |controller| controller[:exist] }.each do |controller|
|
64
|
+
# puts "controller: #{controller[:full_file]}"
|
62
65
|
unless File.exist?(controller[:full_file])
|
63
66
|
log.error 'Controller apparently exists but no file found, this means that you need re-run rake routes'
|
64
67
|
puts controller[:full_file]
|
@@ -66,7 +69,7 @@ class Step7RailsStructureControllers < KDomain::DomainModel::Step
|
|
66
69
|
end
|
67
70
|
controller[:behaviours] = extract_behavior(controller[:full_file])
|
68
71
|
klass_name = controller[:behaviours][:class_name]
|
69
|
-
controller[:functions] = extract_functions(klass_name)
|
72
|
+
controller[:functions] = extract_functions(klass_name, controller[:full_file])
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
@@ -97,13 +100,15 @@ class Step7RailsStructureControllers < KDomain::DomainModel::Step
|
|
97
100
|
shim_loader
|
98
101
|
end
|
99
102
|
|
100
|
-
def extract_functions(klass_name)
|
103
|
+
def extract_functions(klass_name, controller_file)
|
101
104
|
klass = Module.const_get(klass_name.classify)
|
102
105
|
|
103
106
|
class_info = Peeky.api.build_class_info(klass.new)
|
104
107
|
|
105
108
|
class_info.to_h
|
106
109
|
rescue StandardError => e
|
107
|
-
log.
|
110
|
+
log.kv 'controller_file', controller_file
|
111
|
+
log.exception(e, style: :short)
|
112
|
+
{}
|
108
113
|
end
|
109
114
|
end
|