k_domain 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +31 -1
  3. data/STORIES.md +6 -2
  4. data/k_domain.gemspec +2 -0
  5. data/lib/k_domain/domain_model/dtos/_.rb +88 -0
  6. data/lib/k_domain/domain_model/dtos/belongs_to.rb +25 -0
  7. data/lib/k_domain/domain_model/dtos/column_old.rb +225 -0
  8. data/lib/k_domain/domain_model/dtos/dictionary/dictionary.rb +17 -0
  9. data/lib/k_domain/domain_model/dtos/domain.rb +11 -0
  10. data/lib/k_domain/domain_model/dtos/domain_statistics.rb +29 -0
  11. data/lib/k_domain/domain_model/dtos/entity.rb +338 -0
  12. data/lib/k_domain/domain_model/dtos/entity_statistics.rb +22 -0
  13. data/lib/k_domain/domain_model/dtos/foreign_key.rb +17 -0
  14. data/lib/k_domain/domain_model/dtos/has_and_belongs_to_many.rb +20 -0
  15. data/lib/k_domain/domain_model/dtos/has_many.rb +27 -0
  16. data/lib/k_domain/domain_model/dtos/has_one.rb +41 -0
  17. data/lib/k_domain/domain_model/dtos/investigate/investigate.rb +10 -0
  18. data/lib/k_domain/domain_model/dtos/investigate/issue.rb +13 -0
  19. data/lib/k_domain/domain_model/dtos/models/column.rb +49 -0
  20. data/lib/k_domain/domain_model/dtos/models/model.rb +111 -0
  21. data/lib/k_domain/domain_model/dtos/name_options.rb +10 -0
  22. data/lib/k_domain/domain_model/dtos/rails_controller.rb +10 -0
  23. data/lib/k_domain/domain_model/dtos/rails_model.rb +92 -0
  24. data/lib/k_domain/domain_model/dtos/related_entity.rb +36 -0
  25. data/lib/k_domain/domain_model/dtos/schema.rb +12 -0
  26. data/lib/k_domain/domain_model/dtos/statistics.rb +21 -0
  27. data/lib/k_domain/domain_model/dtos/validate.rb +25 -0
  28. data/lib/k_domain/domain_model/dtos/validates.rb +50 -0
  29. data/lib/k_domain/domain_model/load.rb +29 -0
  30. data/lib/k_domain/domain_model/transform.rb +94 -0
  31. data/lib/k_domain/domain_model/transform_steps/_.rb +9 -0
  32. data/lib/k_domain/domain_model/transform_steps/step.rb +123 -0
  33. data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +21 -0
  34. data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +62 -0
  35. data/lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb +137 -0
  36. data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +454 -0
  37. data/lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb +56 -0
  38. data/lib/k_domain/raw_db_schema/dtos/_.rb +14 -0
  39. data/lib/k_domain/raw_db_schema/dtos/column.rb +16 -0
  40. data/lib/k_domain/raw_db_schema/dtos/database.rb +11 -0
  41. data/lib/k_domain/raw_db_schema/dtos/foreign_key.rb +14 -0
  42. data/lib/k_domain/raw_db_schema/dtos/index.rb +14 -0
  43. data/lib/k_domain/raw_db_schema/dtos/schema.rb +18 -0
  44. data/lib/k_domain/raw_db_schema/dtos/table.rb +21 -0
  45. data/lib/k_domain/raw_db_schema/dtos/unique_key.rb +14 -0
  46. data/lib/k_domain/raw_db_schema/load.rb +29 -0
  47. data/lib/k_domain/{raw_schema → raw_db_schema}/template.rb +0 -0
  48. data/lib/k_domain/{raw_schema → raw_db_schema}/transform.rb +37 -21
  49. data/lib/k_domain/version.rb +1 -1
  50. data/lib/k_domain.rb +14 -1
  51. metadata +74 -4
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module RawDbSchema
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
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module RawDbSchema
5
+ class Schema < Dry::Struct
6
+ class Meta < Dry::Struct
7
+ attribute :rails , Types::Strict::Integer
8
+ attribute :database , KDomain::RawDbSchema::Database
9
+ attribute :unique_keys , Types::Strict::Array.of(KDomain::RawDbSchema::UniqueKey)
10
+ end
11
+
12
+ attribute :tables , Types::Strict::Array.of(KDomain::RawDbSchema::Table)
13
+ attribute :foreign_keys? , Types::Strict::Array.of(KDomain::RawDbSchema::ForeignKey)
14
+ attribute :indexes? , Types::Strict::Array.of(KDomain::RawDbSchema::Index)
15
+ attribute :meta , KDomain::RawDbSchema::Schema::Meta
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module RawDbSchema
5
+ class Table < Dry::Struct
6
+ class Meta < 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
+ attribute :name , Types::Strict::String
13
+ attribute :primary_key , Types::Strict::String.optional.default(nil)
14
+ attribute :primary_key_type , Types::Strict::String.optional.default(nil)
15
+ attribute :id? , Types::Nominal::Any.optional.default(nil) # Types::Strict::String.optional.default(nil)
16
+ attribute :columns , Types::Strict::Array.of(KDomain::RawDbSchema::Column)
17
+ attribute :indexes , Types::Strict::Array.of(KDomain::RawDbSchema::Index)
18
+ attribute :rails_schema , KDomain::RawDbSchema::Table::Meta
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module RawDbSchema
5
+ # Keep a track of unique keys that appear in the data structures
6
+ # so that we can track what new attributes to add to the models
7
+ class UniqueKey < Dry::Struct
8
+ attribute :type , Types::Strict::String
9
+ attribute :category , Types::Strict::String.optional
10
+ attribute :key , Types::Strict::String
11
+ attribute :keys , Types::Strict::Array
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Annotates the original schema with methods that implement existing method calls
4
+ # that are already in the schema so that we can build a hash.
5
+ #
6
+ # Writes a new annotated schema.rb file with a public method called load that
7
+ # builds the hash
8
+
9
+ module KDomain
10
+ module RawDbSchema
11
+ class Load
12
+ include KLog::Logging
13
+
14
+ attr_reader :source_file
15
+ attr_reader :data
16
+
17
+ def initialize(source_file)
18
+ @source_file = source_file
19
+ end
20
+
21
+ def call
22
+ json = File.read(source_file)
23
+ data = KUtil.data.json_parse(json, as: :hash_symbolized)
24
+
25
+ @data = KDomain::RawDbSchema::Schema.new(data)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,24 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Annotates the original schema with methods that implement existing method calls
2
4
  # that are already in the schema so that we can build a hash.
3
5
  #
4
6
  # Writes a new annotated schema.rb file with a public method called load that
5
7
  # builds the hash
6
- # frozen_string_literal: true
7
-
8
8
  module KDomain
9
- module RawSchema
9
+ module RawDbSchema
10
10
  class Transform
11
11
  include KLog::Logging
12
12
 
13
13
  attr_reader :source_file
14
14
  attr_reader :template_file
15
- attr_reader :target_ruby_class
16
-
17
- def initialize(source_file)#, target_file)
15
+ attr_reader :schema_loader
16
+
17
+ # , target_file)
18
+ def initialize(source_file)
18
19
  @source_file = source_file
19
- @template_file = 'lib/k_domain/raw_schema/template.rb'
20
+ @template_file = 'lib/k_domain/raw_db_schema/template.rb'
20
21
  end
21
-
22
+
22
23
  def call
23
24
  # log.kv 'source_file', source_file
24
25
  # log.kv 'template_file', template_file
@@ -31,37 +32,52 @@ module KDomain
31
32
  content
32
33
  .gsub!(/ActiveRecord::Schema.define/, 'load')
33
34
 
34
- lines = content.lines.map { |line| " #{line}" }.join()
35
+ lines = content.lines.map { |line| " #{line}" }.join
35
36
 
36
- @target_ruby_class = File
37
- .read(template_file)
38
- .gsub('{{source_file}}', source_file)
39
- .gsub('{{rails_schema}}', lines)
37
+ @schema_loader = File
38
+ .read(template_file)
39
+ .gsub('{{source_file}}', source_file)
40
+ .gsub('{{rails_schema}}', lines)
40
41
  end
41
42
 
42
- def write_target(target_file)
43
- if target_ruby_class.nil?
43
+ # rename to target_ruby
44
+ # This is an internal ruby structure that is evaluated
45
+ # writing is only needed for debugging purposes
46
+ def write_schema_loader(target_file)
47
+ if schema_loader.nil?
44
48
  puts '.call method has not been executed'
45
49
  return
46
50
  end
47
51
 
48
52
  FileUtils.mkdir_p(File.dirname(target_file))
49
- File.write(target_file, target_ruby_class)
53
+ File.write(target_file, schema_loader)
50
54
  end
51
55
 
52
- def json
53
- if target_ruby_class.nil?
56
+ def write_json(json_file)
57
+ if schema_loader.nil?
58
+ puts '.call method has not been executed'
59
+ return
60
+ end
61
+
62
+ FileUtils.mkdir_p(File.dirname(json_file))
63
+ File.write(json_file, JSON.pretty_generate(schema))
64
+ end
65
+
66
+ # rubocop:disable Security/Eval
67
+ def schema
68
+ if schema_loader.nil?
54
69
  puts '.call method has not been executed'
55
70
  return
56
71
  end
57
72
 
58
73
  # load target_file
59
- eval target_ruby_class
60
-
74
+ eval schema_loader
75
+
61
76
  loader = LoadSchema.new
62
- loader.load_schema()
77
+ loader.load_schema
63
78
  loader.schema
64
79
  end
80
+ # rubocop:enable Security/Eval
65
81
  end
66
82
  end
67
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDomain
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.5'
5
5
  end
data/lib/k_domain.rb CHANGED
@@ -1,8 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/string'
4
+ require 'dry-struct'
3
5
  require 'k_log'
4
6
  require 'k_domain/version'
5
- require 'k_domain/raw_schema/transform'
7
+ require 'k_domain/raw_db_schema/dtos/_'
8
+ require 'k_domain/raw_db_schema/transform'
9
+ require 'k_domain/raw_db_schema/load'
10
+ require 'k_domain/domain_model/dtos/_'
11
+ require 'k_domain/domain_model/transform'
12
+ require 'k_domain/domain_model/transform_steps/_'
13
+ require 'k_domain/domain_model/load'
14
+
15
+ # # This is useful if you want to initialize structures via Hash
16
+ # class SymbolizeStruct < Dry::Struct
17
+ # transform_keys(&:to_sym)
18
+ # end
6
19
 
7
20
  module KDomain
8
21
  # raise KDomain::Error, 'Sample message'
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-26 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-struct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: k_log
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,8 +81,50 @@ files:
53
81
  - hooks/update-version
54
82
  - k_domain.gemspec
55
83
  - lib/k_domain.rb
56
- - lib/k_domain/raw_schema/template.rb
57
- - lib/k_domain/raw_schema/transform.rb
84
+ - lib/k_domain/domain_model/dtos/_.rb
85
+ - lib/k_domain/domain_model/dtos/belongs_to.rb
86
+ - lib/k_domain/domain_model/dtos/column_old.rb
87
+ - lib/k_domain/domain_model/dtos/dictionary/dictionary.rb
88
+ - lib/k_domain/domain_model/dtos/domain.rb
89
+ - lib/k_domain/domain_model/dtos/domain_statistics.rb
90
+ - lib/k_domain/domain_model/dtos/entity.rb
91
+ - lib/k_domain/domain_model/dtos/entity_statistics.rb
92
+ - lib/k_domain/domain_model/dtos/foreign_key.rb
93
+ - lib/k_domain/domain_model/dtos/has_and_belongs_to_many.rb
94
+ - lib/k_domain/domain_model/dtos/has_many.rb
95
+ - lib/k_domain/domain_model/dtos/has_one.rb
96
+ - lib/k_domain/domain_model/dtos/investigate/investigate.rb
97
+ - lib/k_domain/domain_model/dtos/investigate/issue.rb
98
+ - lib/k_domain/domain_model/dtos/models/column.rb
99
+ - lib/k_domain/domain_model/dtos/models/model.rb
100
+ - lib/k_domain/domain_model/dtos/name_options.rb
101
+ - lib/k_domain/domain_model/dtos/rails_controller.rb
102
+ - lib/k_domain/domain_model/dtos/rails_model.rb
103
+ - lib/k_domain/domain_model/dtos/related_entity.rb
104
+ - lib/k_domain/domain_model/dtos/schema.rb
105
+ - lib/k_domain/domain_model/dtos/statistics.rb
106
+ - lib/k_domain/domain_model/dtos/validate.rb
107
+ - lib/k_domain/domain_model/dtos/validates.rb
108
+ - lib/k_domain/domain_model/load.rb
109
+ - lib/k_domain/domain_model/transform.rb
110
+ - lib/k_domain/domain_model/transform_steps/_.rb
111
+ - lib/k_domain/domain_model/transform_steps/step.rb
112
+ - lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb
113
+ - lib/k_domain/domain_model/transform_steps/step2_attach_models.rb
114
+ - lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb
115
+ - lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb
116
+ - lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb
117
+ - lib/k_domain/raw_db_schema/dtos/_.rb
118
+ - lib/k_domain/raw_db_schema/dtos/column.rb
119
+ - lib/k_domain/raw_db_schema/dtos/database.rb
120
+ - lib/k_domain/raw_db_schema/dtos/foreign_key.rb
121
+ - lib/k_domain/raw_db_schema/dtos/index.rb
122
+ - lib/k_domain/raw_db_schema/dtos/schema.rb
123
+ - lib/k_domain/raw_db_schema/dtos/table.rb
124
+ - lib/k_domain/raw_db_schema/dtos/unique_key.rb
125
+ - lib/k_domain/raw_db_schema/load.rb
126
+ - lib/k_domain/raw_db_schema/template.rb
127
+ - lib/k_domain/raw_db_schema/transform.rb
58
128
  - lib/k_domain/version.rb
59
129
  homepage: http://appydave.com/gems/k-domain
60
130
  licenses: