k_domain 0.0.16 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) 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/.gitignore +1 -0
  6. data/.rubocop.yml +1 -2
  7. data/Guardfile +1 -0
  8. data/README.md +15 -0
  9. data/STORIES.md +35 -6
  10. data/lib/k_domain/config/_.rb +4 -0
  11. data/lib/k_domain/config/config.rb +19 -0
  12. data/lib/k_domain/config/configuration.rb +76 -0
  13. data/lib/k_domain/domain_model/load.rb +41 -0
  14. data/lib/k_domain/domain_model/transform.rb +27 -55
  15. data/lib/k_domain/domain_model/transform_steps/_.rb +8 -7
  16. data/lib/k_domain/domain_model/transform_steps/step.rb +27 -1
  17. data/lib/k_domain/domain_model/transform_steps/{step1_attach_db_schema.rb → step1_db_schema.rb} +2 -1
  18. data/lib/k_domain/domain_model/transform_steps/{step5_attach_dictionary.rb → step20_dictionary.rb} +7 -4
  19. data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +123 -0
  20. data/lib/k_domain/domain_model/transform_steps/{step8_rails_resource_models.rb → step4_rails_resource_models.rb} +4 -4
  21. data/lib/k_domain/domain_model/transform_steps/step5_rails_resource_routes.rb +36 -0
  22. data/lib/k_domain/domain_model/transform_steps/step6_rails_structure_models.rb +90 -0
  23. data/lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb +111 -0
  24. data/lib/k_domain/domain_model/transform_steps/step8_domain_columns.rb +99 -0
  25. data/lib/k_domain/rails_code_extractor/_.rb +5 -0
  26. data/lib/k_domain/rails_code_extractor/extract_controller.rb +61 -0
  27. data/lib/k_domain/rails_code_extractor/extract_model.rb +56 -6
  28. data/lib/k_domain/rails_code_extractor/{load_shim.rb → shim_loader.rb} +3 -5
  29. data/lib/k_domain/raw_db_schema/load.rb +1 -1
  30. data/lib/k_domain/raw_db_schema/transform.rb +28 -3
  31. data/lib/k_domain/schemas/_.rb +6 -3
  32. data/lib/k_domain/schemas/database.rb +86 -0
  33. data/lib/k_domain/schemas/domain/erd_file.rb +78 -77
  34. data/lib/k_domain/schemas/domain.rb +149 -0
  35. data/lib/k_domain/schemas/domain_model.rb +6 -5
  36. data/lib/k_domain/schemas/{domain/_.rb → domain_types.rb} +1 -8
  37. data/lib/k_domain/schemas/rails_resource.rb +43 -6
  38. data/lib/k_domain/schemas/rails_structure.rb +182 -0
  39. data/lib/k_domain/version.rb +1 -1
  40. data/lib/k_domain.rb +4 -2
  41. data/templates/custom/action_controller.rb +36 -0
  42. data/templates/custom/controller_interceptors.rb +78 -0
  43. data/templates/custom/model_interceptors.rb +71 -0
  44. data/templates/load_schema.rb +7 -0
  45. data/templates/rails/action_controller.rb +301 -0
  46. data/templates/{active_record_shims.rb → rails/active_record.rb} +42 -49
  47. data/templates/ruby_code_extractor/attach_class_info.rb +13 -0
  48. data/templates/ruby_code_extractor/behaviour_accessors.rb +39 -0
  49. data/templates/sample_config.rb +47 -0
  50. data/templates/simple/controller_interceptors.rb +2 -0
  51. metadata +33 -22
  52. data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +0 -62
  53. data/lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb +0 -137
  54. data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +0 -457
  55. data/lib/k_domain/domain_model/transform_steps/step9_rails_structure_models.rb +0 -33
  56. data/lib/k_domain/schemas/database/_.rb +0 -7
  57. data/lib/k_domain/schemas/database/foreign_key.rb +0 -14
  58. data/lib/k_domain/schemas/database/index.rb +0 -14
  59. data/lib/k_domain/schemas/database/schema.rb +0 -31
  60. data/lib/k_domain/schemas/database/table.rb +0 -32
  61. data/lib/k_domain/schemas/domain/domain.rb +0 -11
  62. data/lib/k_domain/schemas/domain/models/column.rb +0 -49
  63. data/lib/k_domain/schemas/domain/models/model.rb +0 -111
  64. data/templates/fake_module_shims.rb +0 -42
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDomain
4
- module Database
5
- class Index < Dry::Struct
6
- attribute :name , Types::Strict::String
7
- attribute :fields , Types::Nominal::Any.optional.default('xxxxx1')
8
- attribute :using , Types::Nominal::String
9
- attribute :order? , Types::Nominal::Hash
10
- attribute :where? , Types::Nominal::Any.optional.default(nil)
11
- attribute :unique? , Types::Nominal::Any.optional.default(nil)
12
- end
13
- end
14
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDomain
4
- module Database
5
- class Schema < Dry::Struct
6
- class DbInfo < Dry::Struct
7
- attribute :type , Types::Strict::String
8
- attribute :version , Types::Nominal::Any.optional.default(nil)
9
- attribute :extensions , Types::Strict::Array
10
- end
11
-
12
- class UniqueKey < Dry::Struct
13
- attribute :type , Types::Strict::String
14
- attribute :category , Types::Strict::String.optional
15
- attribute :key , Types::Strict::String
16
- attribute :keys , Types::Strict::Array
17
- end
18
-
19
- class Meta < Dry::Struct
20
- attribute :rails , Types::Strict::Integer
21
- attribute :db_info , KDomain::Database::Schema::DbInfo
22
- attribute :unique_keys , Types::Strict::Array.of(KDomain::Database::Schema::UniqueKey)
23
- end
24
-
25
- attribute :tables , Types::Strict::Array.of(KDomain::Database::Table)
26
- attribute :foreign_keys? , Types::Strict::Array.of(KDomain::Database::ForeignKey)
27
- attribute :indexes? , Types::Strict::Array.of(KDomain::Database::Index)
28
- attribute :meta , KDomain::Database::Schema::Meta
29
- end
30
- end
31
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDomain
4
- module Database
5
- class Table < Dry::Struct
6
- class RailsSchema < Dry::Struct
7
- attribute :primary_key , Types::Nominal::Any.optional.default(nil)
8
- attribute :id , Types::Nominal::Any.optional.default(nil)
9
- attribute :force , Types::Nominal::Any.optional.default(nil)
10
- end
11
-
12
- class Column < Dry::Struct
13
- attribute :name , Types::Strict::String
14
- attribute :type , Types::Strict::String
15
- attribute :precision? , Types::Strict::Integer.optional.default(nil)
16
- attribute :scale? , Types::Strict::Integer.optional.default(nil)
17
- attribute :default? , Types::Nominal::Any.optional.default(nil)
18
- attribute :array? , Types::Strict::Bool.optional.default(nil)
19
- attribute :null? , Types::Strict::Bool.optional.default(nil)
20
- attribute :limit? , Types::Strict::Integer.optional.default(nil)
21
- end
22
-
23
- attribute :name , Types::Strict::String
24
- attribute :primary_key , Types::Strict::String.optional.default(nil)
25
- attribute :primary_key_type , Types::Strict::String.optional.default(nil)
26
- attribute :id? , Types::Nominal::Any.optional.default(nil)
27
- attribute :columns , Types::Strict::Array.of(KDomain::Database::Table::Column)
28
- attribute :indexes , Types::Strict::Array.of(KDomain::Database::Index) # May want to have a Table::Index, but for now this is a shared scheam
29
- attribute :rails_schema , KDomain::Database::Table::RailsSchema
30
- end
31
- end
32
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Domain class holds a list of the entities
4
- module KDomain
5
- module DomainModel
6
- class Domain < Dry::Struct
7
- attribute :models , Types::Strict::Array.of(KDomain::DomainModel::Model)
8
- attribute :erd_files , Types::Strict::Array.of(KDomain::DomainModel::ErdFile)
9
- end
10
- end
11
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDomain
4
- module DomainModel
5
- class Column < Dry::Struct
6
- attribute :name , Types::Strict::String # "source_account_id"
7
- attribute :name_plural , Types::Strict::String # "source_account_ids"
8
- attribute :type , Types::Coercible::Symbol # "integer"
9
- attribute :precision , Types::Strict::Integer.optional.default(nil) # null
10
- attribute :scale , Types::Strict::Integer.optional.default(nil) # null
11
- attribute :default , Types::Nominal::Any.optional.default(nil) # null
12
- attribute :null , Types::Nominal::Any.optional.default(nil) # null
13
- attribute :limit , Types::Strict::Integer.optional.default(nil) # null
14
- attribute :array , Types::Strict::Bool.optional.default(nil) # null
15
-
16
- # Calculated value
17
- attribute :structure_type , Types::Coercible::Symbol #
18
- attribute :foreign_key , Types::Strict::Bool.optional.default(nil) #
19
- attribute :foreign_table , Types::Strict::String #
20
- attribute :foreign_table_plural , Types::Strict::String #
21
-
22
- # def data_column
23
- # @columns_data ||= structure_type?(:data)
24
- # end
25
-
26
- # def structure_type?(*structure_types)
27
- # structure_types.include?(column.structure_type)
28
- # end
29
-
30
- def db_type
31
- return @db_type if defined? @db_type
32
-
33
- @db_type = DB_TYPE[type] || '******'
34
- end
35
-
36
- def ruby_type
37
- return @ruby_type if defined? @ruby_type
38
-
39
- @ruby_type = RUBY_TYPE[type] || '******'
40
- end
41
-
42
- def csharp_type
43
- return @csharp_type if defined? @csharp_type
44
-
45
- @csharp_type = CSHARP_TYPE[type] || '******'
46
- end
47
- end
48
- end
49
- end
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Domain class holds a list of the entities
4
- module KDomain
5
- module DomainModel
6
- class Model < Dry::Struct
7
- class Pk < Dry::Struct
8
- attribute :name , Types::Strict::String.optional.default(nil)
9
- attribute :type , Types::Strict::String.optional.default(nil)
10
- attribute :exist , Types::Strict::Bool
11
- end
12
-
13
- class ErdLocation < Dry::Struct
14
- attribute :file , Types::Strict::String
15
- attribute :exist , Types::Strict::Bool
16
- attribute :state , Types::Strict::Array
17
- end
18
-
19
- attribute :name , Types::Strict::String
20
- attribute :name_plural , Types::Strict::String
21
- attribute :table_name , Types::Strict::String
22
- # Model type - :entity, :basic_user, :admin_user, possibly: m2m, agg_root
23
- attribute :type , Types::Strict::Symbol.optional.default(:entity)
24
- attribute :pk , KDomain::DomainModel::Model::Pk
25
- attribute :erd_location , KDomain::DomainModel::Model::ErdLocation
26
- attribute :columns , Types::Strict::Array.of(KDomain::DomainModel::Column)
27
-
28
- def ruby?
29
- location.exist
30
- end
31
-
32
- def pk?
33
- pk.exist
34
- end
35
-
36
- # 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
37
- def main_key
38
- @main_key ||= MainKey.lookup(name, columns_data)
39
- end
40
-
41
- def traits
42
- @traits ||= Traits.lookup(name)
43
- end
44
-
45
- # def where()
46
- # end
47
-
48
- # def columns_where()
49
- # end
50
-
51
- # Column filters
52
-
53
- def columns_data
54
- @columns_data ||= columns_for_structure_types(:data)
55
- end
56
-
57
- # def columns_data_optional
58
- # @columns_data_optional ||= columns_for_structure_types(:data).select { |c| true }
59
- # end
60
-
61
- # def columns_data_required
62
- # @columns_data_required ||= columns_for_structure_types(:data).select { |c| false }
63
- # end
64
-
65
- def columns_primary
66
- @columns_primary ||= columns_for_structure_types(:primary_key)
67
- end
68
-
69
- def columns_foreign
70
- @columns_foreign ||= columns_for_structure_types(:foreign_key)
71
- end
72
-
73
- def columns_timestamp
74
- @columns_data_timestamp ||= columns_for_structure_types(:timestamp)
75
- end
76
-
77
- def columns_deleted_at
78
- @columns_data_deleted_at ||= columns_for_structure_types(:deleted_at)
79
- end
80
-
81
- def columns_virtual
82
- @columns_virtual ||= columns_for_structure_types(:timestamp, :deleted_at)
83
- end
84
-
85
- def columns_data_foreign
86
- @columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key)
87
- end
88
- alias rows_fields_and_fk columns_data_foreign
89
-
90
- def columns_data_primary
91
- @columns_data_primary ||= columns_for_structure_types(:data, :primary_key)
92
- end
93
- alias rows_fields_and_pk columns_data_primary
94
-
95
- def columns_data_virtual
96
- @columns_data_virtual ||= columns_for_structure_types(:data, :timestamp, :deleted_at)
97
- end
98
- alias rows_fields_and_virtual columns_data_virtual
99
-
100
- def columns_data_foreign_virtual
101
- @columns_data_foreign_virtual ||= columns_for_structure_types(:data, :foreign_key, :timestamp, :deleted_at)
102
- end
103
-
104
- private
105
-
106
- def columns_for_structure_types(*structure_types)
107
- columns.select { |column| structure_types.include?(column.structure_type) }
108
- end
109
- end
110
- end
111
- end
@@ -1,42 +0,0 @@
1
- class Rails
2
- def self.env; end
3
-
4
- def self.application
5
- OpenStruct.new(secrets: OpenStruct.new(credentials_secret_key: Base64.encode64('ABC')))
6
- end
7
- end
8
-
9
- module ActsAsCommentable
10
- module Comment
11
- end
12
- end
13
-
14
- module Scopes
15
- module CompanyScopes
16
- end
17
- end
18
-
19
- module ActionView
20
- module Helpers
21
- module NumberHelper
22
- end
23
- end
24
- end
25
-
26
- module RailsUpgrade
27
- def rails4?
28
- true
29
- end
30
-
31
- def rails5?
32
- true
33
- end
34
-
35
- def rails6?
36
- true
37
- end
38
-
39
- def belongs_to_required
40
- {}
41
- end
42
- end