k_domain 0.0.2 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +39 -1
  3. data/Gemfile +10 -0
  4. data/Rakefile +3 -1
  5. data/STORIES.md +21 -2
  6. data/k_domain.gemspec +4 -0
  7. data/lib/k_domain/domain_model/load.rb +35 -0
  8. data/lib/k_domain/domain_model/transform.rb +110 -0
  9. data/lib/k_domain/domain_model/transform_steps/_.rb +10 -0
  10. data/lib/k_domain/domain_model/transform_steps/step.rb +142 -0
  11. data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +21 -0
  12. data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +62 -0
  13. data/lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb +137 -0
  14. data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +456 -0
  15. data/lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb +58 -0
  16. data/lib/k_domain/domain_model/transform_steps/step8_locate_rails_models.rb +44 -0
  17. data/lib/k_domain/raw_db_schema/load.rb +35 -0
  18. data/lib/k_domain/{raw_schema → raw_db_schema}/transform.rb +36 -21
  19. data/lib/k_domain/schemas/_.rb +15 -0
  20. data/lib/k_domain/schemas/database/_.rb +7 -0
  21. data/lib/k_domain/schemas/database/foreign_key.rb +14 -0
  22. data/lib/k_domain/schemas/database/index.rb +14 -0
  23. data/lib/k_domain/schemas/database/schema.rb +31 -0
  24. data/lib/k_domain/schemas/database/table.rb +32 -0
  25. data/lib/k_domain/schemas/dictionary.rb +19 -0
  26. data/lib/k_domain/schemas/domain/_.rb +65 -0
  27. data/lib/k_domain/schemas/domain/domain.rb +11 -0
  28. data/lib/k_domain/schemas/domain/erd_file.rb +80 -0
  29. data/lib/k_domain/schemas/domain/models/column.rb +49 -0
  30. data/lib/k_domain/schemas/domain/models/model.rb +111 -0
  31. data/lib/k_domain/schemas/domain/old/belongs_to.rb +25 -0
  32. data/lib/k_domain/schemas/domain/old/column_old.rb +225 -0
  33. data/lib/k_domain/schemas/domain/old/domain_statistics.rb +29 -0
  34. data/lib/k_domain/schemas/domain/old/entity.rb +338 -0
  35. data/lib/k_domain/schemas/domain/old/entity_statistics.rb +22 -0
  36. data/lib/k_domain/schemas/domain/old/foreign_key.rb +17 -0
  37. data/lib/k_domain/schemas/domain/old/has_and_belongs_to_many.rb +20 -0
  38. data/lib/k_domain/schemas/domain/old/has_many.rb +27 -0
  39. data/lib/k_domain/schemas/domain/old/has_one.rb +41 -0
  40. data/lib/k_domain/schemas/domain/old/name_options.rb +10 -0
  41. data/lib/k_domain/schemas/domain/old/rails_controller.rb +10 -0
  42. data/lib/k_domain/schemas/domain/old/rails_model.rb +92 -0
  43. data/lib/k_domain/schemas/domain/old/related_entity.rb +36 -0
  44. data/lib/k_domain/schemas/domain/old/statistics.rb +21 -0
  45. data/lib/k_domain/schemas/domain/old/validate.rb +25 -0
  46. data/lib/k_domain/schemas/domain/old/validates.rb +50 -0
  47. data/lib/k_domain/schemas/domain_model.rb +14 -0
  48. data/lib/k_domain/schemas/investigate.rb +15 -0
  49. data/lib/k_domain/schemas/rails_resource.rb +16 -0
  50. data/lib/k_domain/version.rb +1 -1
  51. data/lib/k_domain.rb +23 -1
  52. data/{lib/k_domain/raw_schema/template.rb → templates/load_schema.rb} +4 -4
  53. metadata +88 -4
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class HasOne
6
+ # KEYS = [:model_name, :model_name_plural, :a_lambda, :class_name, :foreign_key, :primary_key, :infer_key]
7
+ KEYS = %i[a_lambda class_name foreign_key primary_key infer_key code_duplicate].freeze
8
+
9
+ attr_accessor :name
10
+
11
+ attr_accessor :model_name
12
+ attr_accessor :model_name_plural
13
+
14
+ attr_accessor :a_lambda
15
+ attr_accessor :class_name
16
+ attr_accessor :foreign_key
17
+ attr_accessor :primary_key
18
+
19
+ def infer_key
20
+ primary_key.nil? ? "#{name}_id" : primary_key
21
+ end
22
+
23
+ attr_accessor :related_entity
24
+ attr_accessor :code_duplicate
25
+
26
+ def to_h
27
+ {
28
+ name: name,
29
+ model_name: model_name,
30
+ model_name_plural: model_name_plural,
31
+ a_lambda: a_lambda,
32
+ class_name: class_name,
33
+ foreign_key: foreign_key,
34
+ primary_key: primary_key,
35
+ code_duplicate: code_duplicate,
36
+ related_entity: related_entity.to_h
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class NameOptions
6
+ attr_accessor :name
7
+ attr_accessor :options
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class RailsController
6
+ # ToDo
7
+ puts 'do soemtnhi'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ # Rails model represents information that is found the model.rb class in the rails project
6
+ class RailsModel
7
+ attr_accessor :name
8
+ attr_accessor :name_plural
9
+ attr_accessor :name_original
10
+ attr_accessor :documentation_rel_path
11
+ attr_accessor :model_path
12
+
13
+ # @param [Symbol] value The value of ID has different meanings
14
+ # @option value :true Id column exists and it uses an Integer type
15
+ # @option value :false Id column does not exist
16
+ # @option value :bigserial Id column exists and it uses a BigSerial type
17
+ attr_accessor :id
18
+
19
+ attr_accessor :force
20
+ attr_accessor :primary_key
21
+ attr_accessor :quirks
22
+
23
+ attr_accessor :ruby_raw
24
+ attr_accessor :ruby_code
25
+ attr_accessor :ruby_frozen
26
+ attr_accessor :ruby_header
27
+ attr_accessor :ruby_code_public
28
+ attr_accessor :ruby_code_private
29
+
30
+ attr_accessor :default_scope
31
+ attr_accessor :scopes
32
+ attr_accessor :public_class_methods
33
+ attr_accessor :public_instance_methods
34
+ attr_accessor :private_instance_methods
35
+
36
+ # stats
37
+ attr_accessor :time_stamp1
38
+ attr_accessor :time_stamp2
39
+ attr_accessor :time_stamp3
40
+
41
+ def code_length
42
+ ruby_raw&.length
43
+ end
44
+
45
+ def display_quirks
46
+ quirks.join(' ')
47
+ end
48
+
49
+ def exists?
50
+ File.exist?(model_path)
51
+ end
52
+
53
+ def initialize
54
+ @quirks = []
55
+ end
56
+
57
+ def add_quirk(quirk)
58
+ @quirks << quirk
59
+ end
60
+
61
+ def to_h
62
+ {
63
+ name: name,
64
+ name_plural: name_plural,
65
+ name_original: name_original,
66
+ documentation_rel_path: documentation_rel_path,
67
+ model_path: model_path,
68
+ id: id,
69
+ force: force,
70
+ primary_key: primary_key,
71
+ quirks: quirks,
72
+ ruby_raw: ruby_raw,
73
+ ruby_code: ruby_code,
74
+ ruby_frozen: ruby_frozen,
75
+ ruby_header: ruby_header,
76
+ ruby_code_public: ruby_code_public,
77
+ ruby_code_private: ruby_code_private,
78
+ default_scope: default_scope,
79
+ scopes: scopes,
80
+ public_class_methods: public_class_methods,
81
+ public_instance_methods: public_instance_methods,
82
+ private_instance_methods: private_instance_methods,
83
+ time_stamp1: time_stamp1,
84
+ time_stamp2: time_stamp2,
85
+ time_stamp3: time_stamp3,
86
+ code_length: code_length,
87
+ exists: exists?
88
+ }
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class RelatedEntity
6
+ # Name of the entity model
7
+ attr_accessor :name
8
+ attr_accessor :name_plural
9
+ attr_accessor :main_key
10
+
11
+ attr_accessor :trait1
12
+ attr_accessor :trait2
13
+ attr_accessor :trait3
14
+
15
+ def initialize(entity)
16
+ @name = entity.name
17
+ @name_plural = entity.name_plural
18
+ @main_key = entity.main_key
19
+ @trait1 = entity.trait1
20
+ @trait2 = entity.trait2
21
+ @trait3 = entity.trait3
22
+ end
23
+
24
+ def to_h
25
+ {
26
+ name: name,
27
+ name_plural: name_plural,
28
+ main_key: main_key,
29
+ trait1: trait1,
30
+ trait2: trait2,
31
+ trait3: trait3
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ # module KDomain
3
+ # module DomainModel
4
+ # # Rails model represents information that is found the model.rb class in the rails project
5
+ # class Statistics
6
+ # attr_accessor :column_counts
7
+ # attr_accessor :code_counts
8
+ # attr_accessor :code_dsl_counts
9
+ # attr_accessor :data_counts
10
+ # attr_accessor :issues
11
+
12
+ # def initialize(meta)
13
+ # @column_counts = OpenStruct.new(meta[:column_counts])
14
+ # @code_counts = OpenStruct.new(meta[:code_counts])
15
+ # @code_dsl_counts = OpenStruct.new(meta[:code_dsl_counts])
16
+ # @data_counts = OpenStruct.new(meta[:data_counts])
17
+ # @issues = meta[:issues]
18
+ # end
19
+ # end
20
+ # end
21
+ # end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class Validate
6
+ KEYS = [:on].freeze
7
+
8
+ attr_accessor :methods
9
+
10
+ attr_accessor :on
11
+
12
+ def format_on
13
+ for_template(on)
14
+ end
15
+
16
+ def for_template(value)
17
+ return nil if value.nil?
18
+ return value.to_s if value.is_a?(Hash)
19
+ return ":#{value}" if value.is_a?(Symbol)
20
+
21
+ value
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class Validates
6
+ KEYS = %i[length unless format presence].freeze
7
+
8
+ attr_accessor :name
9
+
10
+ attr_accessor :length
11
+ attr_accessor :unless
12
+ attr_accessor :format
13
+ attr_accessor :presence
14
+
15
+ def format_length
16
+ for_template(length)
17
+ end
18
+
19
+ def format_unless
20
+ for_template(self.unless)
21
+ end
22
+
23
+ def format_format
24
+ for_template(self.format)
25
+ end
26
+
27
+ def format_presence
28
+ for_template(presence)
29
+ end
30
+
31
+ def for_template(value)
32
+ return nil if value.nil?
33
+ return value.to_s if value.is_a?(Hash)
34
+ return ":#{value}" if value.is_a?(Symbol)
35
+
36
+ value
37
+ end
38
+
39
+ def to_h
40
+ {
41
+ name: name,
42
+ length: length,
43
+ unless: self.unless,
44
+ format: self.format,
45
+ presence: presence
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # DomainModel holds the entire domain model including database and ancillary information
4
+ module KDomain
5
+ module Schemas
6
+ class DomainModel < Dry::Struct
7
+ attribute :domain , KDomain::DomainModel::Domain
8
+ attribute :database , KDomain::Database::Schema
9
+ attribute :dictionary , KDomain::Schemas::Dictionary
10
+ attribute :rails_resource , KDomain::Schemas::RailsResource
11
+ attribute :investigate , KDomain::Schemas::Investigate
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Domain class holds a dictionary entry
4
+ module KDomain
5
+ module Schemas
6
+ class Investigate < Dry::Struct
7
+ attribute :issues , Types::Strict::Array do
8
+ attribute :step , Types::Strict::String
9
+ attribute :location , Types::Strict::String
10
+ attribute :key , Types::Strict::String.optional.default(nil)
11
+ attribute :message , Types::Strict::String
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Domain class holds a dictionary entry
4
+ module KDomain
5
+ module Schemas
6
+ class RailsResource < Dry::Struct
7
+ attribute :models , Types::Strict::Array do
8
+ attribute :model_name , Types::Strict::String
9
+ attribute :table_name , Types::Strict::String
10
+ attribute :file , Types::Strict::String
11
+ attribute :exist , Types::Strict::Bool
12
+ attribute :state , Types::Strict::String
13
+ end
14
+ end
15
+ end
16
+ 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.15'
5
5
  end
data/lib/k_domain.rb CHANGED
@@ -1,13 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/string'
4
+ require 'dry-struct'
3
5
  require 'k_log'
6
+ require 'peeky'
4
7
  require 'k_domain/version'
5
- require 'k_domain/raw_schema/transform'
8
+ require 'k_domain/schemas/_'
9
+ require 'k_domain/raw_db_schema/transform'
10
+ require 'k_domain/raw_db_schema/load'
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'
9
22
  class Error < StandardError; end
10
23
 
24
+ module Gem
25
+ def self.root
26
+ File.expand_path('..', File.dirname(__FILE__))
27
+ end
28
+ def self.resource(resource_path)
29
+ File.join(root, resource_path)
30
+ end
31
+ end
32
+
11
33
  # Your code goes here...
12
34
  end
13
35
 
@@ -11,7 +11,7 @@ class LoadSchema
11
11
  indexes: [],
12
12
  meta: {
13
13
  rails: @rails_version,
14
- database: {
14
+ db_info: {
15
15
  type: 'postgres',
16
16
  version: nil, # TODO
17
17
  extensions: []
@@ -50,14 +50,14 @@ class LoadSchema
50
50
  sort
51
51
  # code to time
52
52
 
53
- # log.kv 'extensions', schema[:database][:extensions].length
53
+ # log.kv 'extensions', schema[:db_info][:extensions].length
54
54
  # log.kv 'tables', schema[:tables].length
55
55
  # log.kv 'indexes', schema[:indexes].length
56
56
  # # a low foreign_keys count is indicative of not using SQL referential integrity
57
57
  # log.kv 'foreign_keys', schema[:foreign_keys].length
58
58
  # log.kv 'Time Taken', (finish - start)
59
59
 
60
- # puts schema[:database][:extensions]
60
+ # puts schema[:db_info][:extensions]
61
61
  # print_unique_keys(type: :foreign_keys, title: 'unique options for foreign_keys')
62
62
  # print_unique_keys(type: :columns, title: 'unique options for columns')
63
63
  # print_unique_keys(type: :fields, category: :integer , title: 'unique options for column - integer')
@@ -74,7 +74,7 @@ class LoadSchema
74
74
 
75
75
  def enable_extension(name)
76
76
  # puts "enable_extension(#{name})"
77
- schema[:meta][:database][:extensions] << name
77
+ schema[:meta][:db_info][:extensions] << name
78
78
  end
79
79
 
80
80
  def create_table(name, **opts)
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.15
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-10-02 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
@@ -24,6 +52,20 @@ dependencies:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: 0.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: peeky
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.0
27
69
  description: " K Domain builds complex domain schemas by combining the database
28
70
  schema with a rich entity relationship DSLs\n"
29
71
  email:
@@ -53,9 +95,51 @@ files:
53
95
  - hooks/update-version
54
96
  - k_domain.gemspec
55
97
  - lib/k_domain.rb
56
- - lib/k_domain/raw_schema/template.rb
57
- - lib/k_domain/raw_schema/transform.rb
98
+ - lib/k_domain/domain_model/load.rb
99
+ - lib/k_domain/domain_model/transform.rb
100
+ - lib/k_domain/domain_model/transform_steps/_.rb
101
+ - lib/k_domain/domain_model/transform_steps/step.rb
102
+ - lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb
103
+ - lib/k_domain/domain_model/transform_steps/step2_attach_models.rb
104
+ - lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb
105
+ - lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb
106
+ - lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb
107
+ - lib/k_domain/domain_model/transform_steps/step8_locate_rails_models.rb
108
+ - lib/k_domain/raw_db_schema/load.rb
109
+ - lib/k_domain/raw_db_schema/transform.rb
110
+ - lib/k_domain/schemas/_.rb
111
+ - lib/k_domain/schemas/database/_.rb
112
+ - lib/k_domain/schemas/database/foreign_key.rb
113
+ - lib/k_domain/schemas/database/index.rb
114
+ - lib/k_domain/schemas/database/schema.rb
115
+ - lib/k_domain/schemas/database/table.rb
116
+ - lib/k_domain/schemas/dictionary.rb
117
+ - lib/k_domain/schemas/domain/_.rb
118
+ - lib/k_domain/schemas/domain/domain.rb
119
+ - lib/k_domain/schemas/domain/erd_file.rb
120
+ - lib/k_domain/schemas/domain/models/column.rb
121
+ - lib/k_domain/schemas/domain/models/model.rb
122
+ - lib/k_domain/schemas/domain/old/belongs_to.rb
123
+ - lib/k_domain/schemas/domain/old/column_old.rb
124
+ - lib/k_domain/schemas/domain/old/domain_statistics.rb
125
+ - lib/k_domain/schemas/domain/old/entity.rb
126
+ - lib/k_domain/schemas/domain/old/entity_statistics.rb
127
+ - lib/k_domain/schemas/domain/old/foreign_key.rb
128
+ - lib/k_domain/schemas/domain/old/has_and_belongs_to_many.rb
129
+ - lib/k_domain/schemas/domain/old/has_many.rb
130
+ - lib/k_domain/schemas/domain/old/has_one.rb
131
+ - lib/k_domain/schemas/domain/old/name_options.rb
132
+ - lib/k_domain/schemas/domain/old/rails_controller.rb
133
+ - lib/k_domain/schemas/domain/old/rails_model.rb
134
+ - lib/k_domain/schemas/domain/old/related_entity.rb
135
+ - lib/k_domain/schemas/domain/old/statistics.rb
136
+ - lib/k_domain/schemas/domain/old/validate.rb
137
+ - lib/k_domain/schemas/domain/old/validates.rb
138
+ - lib/k_domain/schemas/domain_model.rb
139
+ - lib/k_domain/schemas/investigate.rb
140
+ - lib/k_domain/schemas/rails_resource.rb
58
141
  - lib/k_domain/version.rb
142
+ - templates/load_schema.rb
59
143
  homepage: http://appydave.com/gems/k-domain
60
144
  licenses:
61
145
  - MIT