k_domain 0.0.16 → 0.0.26
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/.gitignore +1 -0
- data/.rubocop.yml +1 -2
- data/Guardfile +1 -0
- data/README.md +15 -0
- data/STORIES.md +35 -6
- 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/load.rb +41 -0
- data/lib/k_domain/domain_model/transform.rb +27 -55
- data/lib/k_domain/domain_model/transform_steps/_.rb +8 -7
- data/lib/k_domain/domain_model/transform_steps/step.rb +27 -1
- 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 -4
- data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +123 -0
- data/lib/k_domain/domain_model/transform_steps/{step8_rails_resource_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 +111 -0
- data/lib/k_domain/domain_model/transform_steps/step8_domain_columns.rb +99 -0
- data/lib/k_domain/rails_code_extractor/_.rb +5 -0
- data/lib/k_domain/rails_code_extractor/extract_controller.rb +61 -0
- data/lib/k_domain/rails_code_extractor/extract_model.rb +56 -6
- data/lib/k_domain/rails_code_extractor/{load_shim.rb → shim_loader.rb} +3 -5
- data/lib/k_domain/raw_db_schema/load.rb +1 -1
- data/lib/k_domain/raw_db_schema/transform.rb +28 -3
- data/lib/k_domain/schemas/_.rb +6 -3
- data/lib/k_domain/schemas/database.rb +86 -0
- data/lib/k_domain/schemas/domain/erd_file.rb +78 -77
- data/lib/k_domain/schemas/domain.rb +149 -0
- data/lib/k_domain/schemas/domain_model.rb +6 -5
- data/lib/k_domain/schemas/{domain/_.rb → domain_types.rb} +1 -8
- data/lib/k_domain/schemas/rails_resource.rb +43 -6
- data/lib/k_domain/schemas/rails_structure.rb +182 -0
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +4 -2
- 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/rails/action_controller.rb +301 -0
- data/templates/{active_record_shims.rb → rails/active_record.rb} +42 -49
- data/templates/ruby_code_extractor/attach_class_info.rb +13 -0
- data/templates/ruby_code_extractor/behaviour_accessors.rb +39 -0
- data/templates/sample_config.rb +47 -0
- data/templates/simple/controller_interceptors.rb +2 -0
- metadata +33 -22
- data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +0 -62
- data/lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb +0 -137
- data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +0 -457
- data/lib/k_domain/domain_model/transform_steps/step9_rails_structure_models.rb +0 -33
- 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
- data/templates/fake_module_shims.rb +0 -42
@@ -7,16 +7,29 @@
|
|
7
7
|
# builds the hash
|
8
8
|
module KDomain
|
9
9
|
module RawDbSchema
|
10
|
+
# class TransformFilter
|
11
|
+
# attr_accessor :take
|
12
|
+
# def initialize(take: :all)
|
13
|
+
# @take = take
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
|
10
17
|
class Transform
|
11
18
|
include KLog::Logging
|
12
19
|
|
13
20
|
attr_reader :source_file
|
14
|
-
|
21
|
+
attr_accessor :template_file
|
15
22
|
attr_reader :schema_loader
|
23
|
+
attr_reader :filter
|
16
24
|
|
17
|
-
|
25
|
+
# @param [String] source_file Rails Schema file
|
26
|
+
# @param [OpenStruct] filter Settings for filtering data before transformation, this is useful during debugging
|
27
|
+
# examples
|
28
|
+
# filter = os(run: 1, tables: os(offset: 10, limit: 10))
|
29
|
+
def initialize(source_file, filter)
|
18
30
|
@source_file = source_file
|
19
31
|
@template_file = KDomain::Gem.resource('templates/load_schema.rb')
|
32
|
+
@filter = filter
|
20
33
|
end
|
21
34
|
|
22
35
|
def call
|
@@ -24,6 +37,7 @@ module KDomain
|
|
24
37
|
# log.kv 'template_file', template_file
|
25
38
|
# log.kv 'source_file?', File.exist?(source_file)
|
26
39
|
# log.kv 'template_file?', File.exist?(template_file)
|
40
|
+
|
27
41
|
log.error "Template not found: #{template_file}" unless File.exist?(template_file)
|
28
42
|
|
29
43
|
content = File.read(source_file)
|
@@ -72,11 +86,22 @@ module KDomain
|
|
72
86
|
|
73
87
|
loader = LoadSchema.new
|
74
88
|
loader.load_schema
|
75
|
-
|
89
|
+
|
90
|
+
apply_filter(loader.schema)
|
76
91
|
rescue StandardError => e
|
77
92
|
log.exception(e)
|
78
93
|
end
|
79
94
|
# rubocop:enable Security/Eval
|
95
|
+
|
96
|
+
# rubocop:disable Metrics/AbcSize
|
97
|
+
def apply_filter(schema)
|
98
|
+
return schema unless filter.active == 1
|
99
|
+
|
100
|
+
schema[:tables] = schema[:tables].slice(filter.table.offset, filter.table.limit) || [] if filter.table.offset.is_a?(Integer) && filter.table.limit.is_a?(Integer)
|
101
|
+
|
102
|
+
schema
|
103
|
+
end
|
104
|
+
# rubocop:enable Metrics/AbcSize
|
80
105
|
end
|
81
106
|
end
|
82
107
|
end
|
data/lib/k_domain/schemas/_.rb
CHANGED
@@ -7,9 +7,12 @@ module Types
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require_relative 'rails_resource'
|
10
|
+
require_relative 'rails_structure'
|
10
11
|
require_relative 'investigate'
|
11
|
-
require_relative 'database
|
12
|
+
require_relative 'database'
|
12
13
|
require_relative 'dictionary'
|
13
|
-
require_relative '
|
14
|
+
require_relative 'domain_types'
|
15
|
+
require_relative 'domain'
|
16
|
+
require_relative 'domain_model'
|
14
17
|
|
15
|
-
require_relative './domain_model'
|
18
|
+
# require_relative './domain_model'
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# KDomain::Schemas::Domain::Column
|
4
|
+
# KDomain::Schemas::Domain::Model
|
5
|
+
|
6
|
+
module KDomain
|
7
|
+
module Schemas
|
8
|
+
class Database < Dry::Struct
|
9
|
+
class ForeignKey < Dry::Struct
|
10
|
+
attribute :left , Types::Strict::String
|
11
|
+
attribute :right , Types::Strict::String
|
12
|
+
attribute :name? , Types::Strict::String.optional.default(nil)
|
13
|
+
attribute :on_update? , Types::Strict::String.optional.default(nil)
|
14
|
+
attribute :on_delete? , Types::Strict::String.optional.default(nil)
|
15
|
+
attribute :column? , Types::Strict::String.optional.default(nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Index < Dry::Struct
|
19
|
+
attribute :name , Types::Strict::String
|
20
|
+
attribute :fields , Types::Nominal::Any.optional.default('xxxxx1')
|
21
|
+
attribute :using , Types::Nominal::String
|
22
|
+
attribute :order? , Types::Nominal::Hash
|
23
|
+
attribute :where? , Types::Nominal::Any.optional.default(nil)
|
24
|
+
attribute :unique? , Types::Nominal::Any.optional.default(nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
class View < Dry::Struct
|
28
|
+
attribute :name , Types::Strict::String
|
29
|
+
attribute :materialized , Types::Strict::Bool
|
30
|
+
attribute :sql_definition , Types::Nominal::String
|
31
|
+
end
|
32
|
+
|
33
|
+
class Table < Dry::Struct
|
34
|
+
class RailsSchema < Dry::Struct
|
35
|
+
attribute :primary_key , Types::Nominal::Any.optional.default(nil)
|
36
|
+
attribute :id , Types::Nominal::Any.optional.default(nil)
|
37
|
+
attribute :force , Types::Nominal::Any.optional.default(nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
class Column < Dry::Struct
|
41
|
+
attribute :name , Types::Strict::String
|
42
|
+
attribute :type , Types::Strict::String
|
43
|
+
attribute :precision? , Types::Strict::Integer.optional.default(nil)
|
44
|
+
attribute :scale? , Types::Strict::Integer.optional.default(nil)
|
45
|
+
attribute :default? , Types::Nominal::Any.optional.default(nil)
|
46
|
+
attribute :array? , Types::Strict::Bool.optional.default(nil)
|
47
|
+
attribute :null? , Types::Strict::Bool.optional.default(nil)
|
48
|
+
attribute :limit? , Types::Strict::Integer.optional.default(nil)
|
49
|
+
end
|
50
|
+
|
51
|
+
attribute :name , Types::Strict::String
|
52
|
+
attribute :primary_key , Types::Strict::String.optional.default(nil)
|
53
|
+
attribute :primary_key_type , Types::Strict::String.optional.default(nil)
|
54
|
+
attribute :id? , Types::Nominal::Any.optional.default(nil)
|
55
|
+
attribute :columns , Types::Strict::Array.of(KDomain::Schemas::Database::Table::Column)
|
56
|
+
attribute :indexes , Types::Strict::Array.of(KDomain::Schemas::Database::Index)
|
57
|
+
attribute :rails_schema , KDomain::Schemas::Database::Table::RailsSchema
|
58
|
+
end
|
59
|
+
|
60
|
+
class DbInfo < Dry::Struct
|
61
|
+
attribute :type , Types::Strict::String
|
62
|
+
attribute :version , Types::Nominal::Any.optional.default(nil)
|
63
|
+
attribute :extensions , Types::Strict::Array
|
64
|
+
end
|
65
|
+
|
66
|
+
class UniqueKey < Dry::Struct
|
67
|
+
attribute :type , Types::Strict::String
|
68
|
+
attribute :category , Types::Strict::String.optional
|
69
|
+
attribute :key , Types::Strict::String
|
70
|
+
attribute :keys , Types::Strict::Array
|
71
|
+
end
|
72
|
+
|
73
|
+
class Meta < Dry::Struct
|
74
|
+
attribute :rails , Types::Strict::Integer
|
75
|
+
attribute :db_info , KDomain::Schemas::Database::DbInfo
|
76
|
+
attribute :unique_keys , Types::Strict::Array.of(KDomain::Schemas::Database::UniqueKey)
|
77
|
+
end
|
78
|
+
|
79
|
+
attribute :tables , Types::Strict::Array.of(KDomain::Schemas::Database::Table)
|
80
|
+
attribute :foreign_keys? , Types::Strict::Array.of(KDomain::Schemas::Database::ForeignKey)
|
81
|
+
attribute :indexes? , Types::Strict::Array.of(KDomain::Schemas::Database::Index)
|
82
|
+
attribute :views? , Types::Strict::Array.of(KDomain::Schemas::Database::View)
|
83
|
+
attribute :meta , KDomain::Schemas::Database::Meta
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -1,82 +1,83 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# # frozen_string_literal: true
|
2
3
|
|
3
|
-
# Domain class holds a list of the entities
|
4
|
-
module KDomain
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
# # Domain class holds a list of the entities
|
5
|
+
# module KDomain
|
6
|
+
# module DomainModel
|
7
|
+
#
|
8
|
+
# class ErdFile < Dry::Struct
|
9
|
+
# attribute :name , Types::Strict::String
|
10
|
+
# attribute :name_plural , Types::Strict::String
|
11
|
+
# attribute :dsl_file , Types::Strict::String
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# attribute? :source , Dry::Struct.optional.default(nil) do
|
14
|
+
# attribute :ruby , Types::Strict::String
|
15
|
+
# attribute :public , Types::Strict::String.optional.default(nil)
|
16
|
+
# attribute :private , Types::Strict::String.optional.default(nil)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
18
|
+
# attribute? :all_methods , Dry::Struct.optional.default(nil) do
|
19
|
+
# attribute? :klass , Types::Strict::Array do
|
20
|
+
# attribute :name , Types::Strict::String
|
21
|
+
# attribute :scope , Types::Strict::String # .optional.default(nil)
|
22
|
+
# attribute :class_method , Types::Strict::Bool
|
23
|
+
# attribute :arguments , Types::Strict::String
|
24
|
+
# end
|
25
|
+
# attribute? :instance , Types::Strict::Array do
|
26
|
+
# attribute :name , Types::Strict::String
|
27
|
+
# attribute :scope , Types::Strict::String # .optional.default(nil)
|
28
|
+
# attribute :class_method , Types::Strict::Bool
|
29
|
+
# attribute :arguments , Types::Strict::String
|
30
|
+
# end
|
31
|
+
# attribute? :instance_public , Types::Strict::Array do
|
32
|
+
# attribute :name , Types::Strict::String
|
33
|
+
# attribute :scope , Types::Strict::String # .optional.default(nil)
|
34
|
+
# attribute :class_method , Types::Strict::Bool
|
35
|
+
# attribute :arguments , Types::Strict::String
|
36
|
+
# end
|
37
|
+
# attribute? :instance_private , Types::Strict::Array do
|
38
|
+
# attribute :name , Types::Strict::String
|
39
|
+
# attribute :scope , Types::Strict::String # .optional.default(nil)
|
40
|
+
# attribute :class_method , Types::Strict::Bool
|
41
|
+
# attribute :arguments , Types::Strict::String
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
# attribute? :dsl , Dry::Struct.optional.default(nil) do
|
46
|
+
# attribute :default_scope , Types::Strict::String.optional.default(nil)
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
48
|
+
# attribute? :scopes , Types::Strict::Array do
|
49
|
+
# attribute :name , Types::Strict::String
|
50
|
+
# attribute :scope , Types::Strict::String # .optional.default(nil)
|
51
|
+
# end
|
52
|
+
# attribute? :belongs_to , Types::Strict::Array do
|
53
|
+
# attribute :name , Types::Strict::String
|
54
|
+
# attribute :options , Types::Strict::Hash.optional.default({}.freeze)
|
55
|
+
# attribute :raw_options , Types::Strict::String
|
56
|
+
# end
|
57
|
+
# attribute? :has_one , Types::Strict::Array do
|
58
|
+
# attribute :name , Types::Strict::String
|
59
|
+
# attribute :options , Types::Strict::Hash.optional.default({}.freeze)
|
60
|
+
# attribute :raw_options , Types::Strict::String
|
61
|
+
# end
|
62
|
+
# attribute? :has_many , Types::Strict::Array do
|
63
|
+
# attribute :name , Types::Strict::String
|
64
|
+
# attribute :options , Types::Strict::Hash.optional.default({}.freeze)
|
65
|
+
# attribute :raw_options , Types::Strict::String
|
66
|
+
# end
|
67
|
+
# attribute? :has_and_belongs_to_many , Types::Strict::Array do
|
68
|
+
# attribute :name , Types::Strict::String
|
69
|
+
# attribute :options , Types::Strict::Hash.optional.default({}.freeze)
|
70
|
+
# attribute :raw_options , Types::Strict::String
|
71
|
+
# end
|
72
|
+
# attribute? :validate_on , Types::Strict::Array do
|
73
|
+
# attribute :line , Types::Strict::String
|
74
|
+
# end
|
75
|
+
# attribute? :validates_on , Types::Strict::Array do
|
76
|
+
# attribute :name , Types::Strict::String
|
77
|
+
# attribute :raw_options , Types::Strict::String
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
# # rubocop:enable Metrics/BlockLength
|
82
|
+
# end
|
83
|
+
# end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain class holds a list of the entities
|
4
|
+
module KDomain
|
5
|
+
module Schemas
|
6
|
+
class Domain < Dry::Struct
|
7
|
+
class Model < Dry::Struct
|
8
|
+
class Relationship < KDomain::Schemas::RailsStructure::NameOptsType
|
9
|
+
attribute :relation_type , Types::Coercible::Symbol
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"#{relation_type}: :#{name} fk: #{opts[:foreign_key]}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Column < Dry::Struct
|
17
|
+
attribute :name , Types::Strict::String # "source_account_id"
|
18
|
+
attribute :name_plural , Types::Strict::String # "source_account_ids"
|
19
|
+
attribute :type , Types::Coercible::Symbol # "integer"
|
20
|
+
attribute :precision , Types::Strict::Integer.optional.default(nil) # null
|
21
|
+
attribute :scale , Types::Strict::Integer.optional.default(nil) # null
|
22
|
+
attribute :default , Types::Nominal::Any.optional.default(nil) # null
|
23
|
+
attribute :null , Types::Nominal::Any.optional.default(nil) # null
|
24
|
+
attribute :limit , Types::Strict::Integer.optional.default(nil) # null
|
25
|
+
attribute :array , Types::Strict::Bool.optional.default(nil) # null
|
26
|
+
|
27
|
+
# Calculated value
|
28
|
+
attribute :structure_type , Types::Coercible::Symbol
|
29
|
+
|
30
|
+
# Any column may have a bunch of related models using various relationship types (belong_to, has_one, has_many etc...)
|
31
|
+
attr_accessor :relationships
|
32
|
+
|
33
|
+
def db_type
|
34
|
+
return @db_type if defined? @db_type
|
35
|
+
|
36
|
+
@db_type = KDomain::Schemas::DB_TYPE[type] || '******'
|
37
|
+
end
|
38
|
+
|
39
|
+
def ruby_type
|
40
|
+
return @ruby_type if defined? @ruby_type
|
41
|
+
|
42
|
+
@ruby_type = KDomain::Schemas::RUBY_TYPE[type] || '******'
|
43
|
+
end
|
44
|
+
|
45
|
+
def csharp_type
|
46
|
+
return @csharp_type if defined? @csharp_type
|
47
|
+
|
48
|
+
@csharp_type = KDomain::Schemas::CSHARP_TYPE[type] || '******'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Pk < Dry::Struct
|
53
|
+
attribute :name , Types::Strict::String.optional.default(nil)
|
54
|
+
attribute :type , Types::Strict::String.optional.default(nil)
|
55
|
+
attribute :exist , Types::Strict::Bool
|
56
|
+
end
|
57
|
+
|
58
|
+
attribute :name , Types::Strict::String
|
59
|
+
attribute :name_plural , Types::Strict::String
|
60
|
+
attribute :table_name , Types::Strict::String
|
61
|
+
# Model type - :entity, :basic_user, :admin_user, possibly: m2m, agg_root
|
62
|
+
attribute :type , Types::Strict::Symbol.optional.default(:entity)
|
63
|
+
attribute :pk , KDomain::Schemas::Domain::Model::Pk
|
64
|
+
attribute :columns , Types::Strict::Array.of(KDomain::Schemas::Domain::Model::Column)
|
65
|
+
attribute :file , Types::Strict::String.optional.default(nil)
|
66
|
+
|
67
|
+
# Link <KDomain::Schemas::RailsStructure::Model> to the domain model
|
68
|
+
attr_accessor :rails_model
|
69
|
+
|
70
|
+
def ruby?
|
71
|
+
file && File.exist?(file)
|
72
|
+
end
|
73
|
+
|
74
|
+
def pk?
|
75
|
+
pk.exist
|
76
|
+
end
|
77
|
+
|
78
|
+
# Custom model configurations such as main_key and traits
|
79
|
+
def config
|
80
|
+
@config ||= KDomain.configuration.find_model(name.to_sym)
|
81
|
+
end
|
82
|
+
|
83
|
+
# If filled in, the model has a main field that is useful for rendering and may be used for unique constraint, may also be called display_name
|
84
|
+
def main_key
|
85
|
+
@main_key ||= config.main_key || KDomain.configuration.fallback_key(columns_data)
|
86
|
+
end
|
87
|
+
|
88
|
+
def traits
|
89
|
+
config.traits
|
90
|
+
end
|
91
|
+
|
92
|
+
def columns_data
|
93
|
+
@columns_data ||= columns_for_structure_types(:data)
|
94
|
+
end
|
95
|
+
|
96
|
+
def columns_primary
|
97
|
+
@columns_primary ||= columns_for_structure_types(:primary_key)
|
98
|
+
end
|
99
|
+
|
100
|
+
def columns_foreign
|
101
|
+
@columns_foreign ||= columns_for_structure_types(:foreign_key)
|
102
|
+
end
|
103
|
+
|
104
|
+
def columns_foreign_type
|
105
|
+
@columns_foreign_type ||= columns_for_structure_types(:foreign_type)
|
106
|
+
end
|
107
|
+
|
108
|
+
def columns_timestamp
|
109
|
+
@columns_data_timestamp ||= columns_for_structure_types(:timestamp)
|
110
|
+
end
|
111
|
+
|
112
|
+
def columns_deleted_at
|
113
|
+
@columns_data_deleted_at ||= columns_for_structure_types(:deleted_at)
|
114
|
+
end
|
115
|
+
|
116
|
+
def columns_virtual
|
117
|
+
@columns_virtual ||= columns_for_structure_types(:foreign_type, :timestamp, :deleted_at)
|
118
|
+
end
|
119
|
+
|
120
|
+
def columns_data_foreign
|
121
|
+
@columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key)
|
122
|
+
end
|
123
|
+
alias rows_fields_and_fk columns_data_foreign
|
124
|
+
|
125
|
+
def columns_data_primary
|
126
|
+
@columns_data_primary ||= columns_for_structure_types(:data, :primary_key)
|
127
|
+
end
|
128
|
+
alias rows_fields_and_pk columns_data_primary
|
129
|
+
|
130
|
+
def columns_data_virtual
|
131
|
+
@columns_data_virtual ||= columns_for_structure_types(:data, :foreign_type, :timestamp, :deleted_at)
|
132
|
+
end
|
133
|
+
alias rows_fields_and_virtual columns_data_virtual
|
134
|
+
|
135
|
+
def columns_data_foreign_virtual
|
136
|
+
@columns_data_foreign_virtual ||= columns_for_structure_types(:data, :foreign_key, :foreign_type, :timestamp, :deleted_at)
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def columns_for_structure_types(*structure_types)
|
142
|
+
columns.select { |column| structure_types.include?(column.structure_type) }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
attribute :models , Types::Strict::Array.of(KDomain::Schemas::Domain::Model)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -4,11 +4,12 @@
|
|
4
4
|
module KDomain
|
5
5
|
module Schemas
|
6
6
|
class DomainModel < Dry::Struct
|
7
|
-
attribute :domain
|
8
|
-
attribute :database
|
9
|
-
attribute :dictionary
|
10
|
-
attribute :rails_resource
|
11
|
-
attribute :
|
7
|
+
attribute :domain , KDomain::Schemas::Domain
|
8
|
+
attribute :database , KDomain::Schemas::Database
|
9
|
+
attribute :dictionary , KDomain::Schemas::Dictionary
|
10
|
+
attribute :rails_resource , KDomain::Schemas::RailsResource
|
11
|
+
attribute :rails_structure , KDomain::Schemas::RailsStructure
|
12
|
+
attribute :investigate , KDomain::Schemas::Investigate
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -1,14 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# log.warn 'models->domain' if AppDebug.require?
|
4
|
-
|
5
|
-
require_relative './models/column'
|
6
|
-
require_relative './models/model'
|
7
|
-
require_relative './erd_file'
|
8
|
-
require_relative './domain'
|
9
|
-
|
10
3
|
module KDomain
|
11
|
-
module
|
4
|
+
module Schemas
|
12
5
|
RUBY_TYPE = {
|
13
6
|
text: 'String',
|
14
7
|
string: 'String',
|
@@ -3,13 +3,50 @@
|
|
3
3
|
# Domain class holds a dictionary entry
|
4
4
|
module KDomain
|
5
5
|
module Schemas
|
6
|
+
# Route related files
|
7
|
+
module Types
|
8
|
+
include Dry.Types()
|
9
|
+
|
10
|
+
Verb = Strict::String.enum('', 'GET', 'PATCH', 'POST', 'PUT', 'DELETE')
|
11
|
+
end
|
12
|
+
|
13
|
+
class Route < Dry::Struct
|
14
|
+
attribute :name , Types::String
|
15
|
+
attribute :controller_name , Types::String
|
16
|
+
attribute :controller_path , Types::String
|
17
|
+
attribute :controller_namespace , Types::String
|
18
|
+
attribute :controller_file , Types::String
|
19
|
+
attribute :controller_exist , Types::Bool
|
20
|
+
attribute :action , Types::String.optional
|
21
|
+
attribute :uri_path , Types::String
|
22
|
+
attribute :mime_match , Types::String
|
23
|
+
attribute :verbs , Types.Array(Types::Verb)
|
24
|
+
attribute :file , Types::String
|
25
|
+
attribute :exist , Types::Bool
|
26
|
+
attribute :duplicate_verb , Types::Bool
|
27
|
+
end
|
28
|
+
|
29
|
+
# Model related files
|
30
|
+
class Model < Dry::Struct
|
31
|
+
attribute :model_name , Types::String
|
32
|
+
attribute :table_name , Types::String
|
33
|
+
attribute :file , Types::String
|
34
|
+
attribute :exist , Types::Bool
|
35
|
+
attribute :state , Types::String
|
36
|
+
end
|
37
|
+
|
6
38
|
class RailsResource < Dry::Struct
|
7
|
-
attribute :models
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
39
|
+
attribute :models, Types.Array(Model)
|
40
|
+
attribute :routes, Types.Array(Route)
|
41
|
+
|
42
|
+
# def find_route(name)
|
43
|
+
# name = name.to_s
|
44
|
+
# routes.find { |route| route.name.to_s == name }
|
45
|
+
# end
|
46
|
+
|
47
|
+
def find_model(name)
|
48
|
+
name = name.to_s
|
49
|
+
models.find { |model| model.model_name.to_s == name }
|
13
50
|
end
|
14
51
|
end
|
15
52
|
end
|