k_domain 0.0.11 → 0.0.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0641cc1145379d1ba83cad6765dbf85bd50bb40ce69105a977eb9ced5326046
4
- data.tar.gz: ac7f352029bcea76171cf87ccf56212e11b3173256519394cc2802e21fd47981
3
+ metadata.gz: c236bd2b714a21b40f5727765bc2b9c049f0c265e7c592e5864a6a6e34330b37
4
+ data.tar.gz: 8ecf79ec6e1805ad6660218ac6aa6931ef67a48b3ca56dd339c7a6a0f6c50886
5
5
  SHA512:
6
- metadata.gz: d2b9ce5ced5669eb620f9c3735fbbaf06e12b6c9f9e5eb6507d3526aefcfe5eb624ce5361a14bc39c2c8449eaa31b3e0caa082b6fca07fba23b166be550fc023
7
- data.tar.gz: a22f3ee11a7b7ef9a9793d01237c5e14f0ed89972d91ede7ed87c29c260b57fca1445ea1bac92830d2299767335e49dc41f2f7b6917a7e08ffb5f8383bbf2ed4
6
+ metadata.gz: 4b3a6c9c9af39c37fdeba462a209a0bd395a72c1887505c0852f1f37a58406c929cc080c63bb9ed5b4de937be51d722e0511a6194d7de389840cb5ca831e7135
7
+ data.tar.gz: f71d09378bf35ec9146692bd137b02176095ba934fbba711c6204896541af27365aeeeb67997d89d43cea7498f2d7361322cba566dd0c31ed1674fb190656968
data/Rakefile CHANGED
@@ -26,7 +26,9 @@ task :publish do
26
26
  system 'gem build'
27
27
  system "gem push #{GEM_NAME}-#{KDomain::VERSION}.gem"
28
28
  end
29
-
29
+ task :build do
30
+ system 'gem build'
31
+ end
30
32
  desc 'Remove old *.gem files'
31
33
  task :clean do
32
34
  system 'rm *.gem'
data/k_domain.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  f.match(%r{^(test|spec|features)/})
34
34
  end
35
35
  end
36
+
36
37
  spec.bindir = 'exe'
37
38
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
39
  spec.require_paths = ['lib']
@@ -22,7 +22,7 @@ module KDomain
22
22
  json = File.read(source_file)
23
23
  data = KUtil.data.json_parse(json, as: :hash_symbolized)
24
24
 
25
- @data = KDomain::DomainModel::Schema.new(data)
25
+ @data = KDomain::Schemas::DomainModel.new(data)
26
26
  end
27
27
  end
28
28
  end
@@ -13,7 +13,7 @@ module KDomain
13
13
  attr_reader :target_file
14
14
  attr_reader :erd_path
15
15
 
16
- def initialize(db_schema, target_file, target_step_file, erd_path)
16
+ def initialize(db_schema: , target_file: , target_step_file: , erd_path:)
17
17
  @db_schema = db_schema
18
18
  @target_step_file = target_step_file
19
19
  @target_file = target_file
@@ -82,16 +82,18 @@ module KDomain
82
82
  domain: {
83
83
  models: [],
84
84
  erd_files: [],
85
- dictionary: []
86
85
  },
87
86
  rails: {
88
87
  models: [],
89
88
  controllers: [],
90
89
  },
91
- rails_files: {
90
+ rails_resource: {
92
91
  models: [],
93
92
  controllers: [],
94
93
  },
94
+ dictionary: {
95
+ items: []
96
+ },
95
97
  database: {
96
98
  tables: [],
97
99
  indexes: [],
@@ -44,22 +44,22 @@ module KDomain
44
44
  end
45
45
 
46
46
  # Rails File Accessor/Helpers
47
- def rails_files
48
- guard('rails_files is missing') if domain_data[:rails_files].nil?
47
+ def rails_resource
48
+ guard('rails_resource is missing') if domain_data[:rails_resource].nil?
49
49
 
50
- domain_data[:rails_files]
50
+ domain_data[:rails_resource]
51
51
  end
52
52
 
53
- def rails_files_models
54
- rails_files[:models]
53
+ def rails_resource_models
54
+ rails_resource[:models]
55
55
  end
56
56
 
57
- def rails_files_models=(value)
58
- rails_files[:models] = value
57
+ def rails_resource_models=(value)
58
+ rails_resource[:models] = value
59
59
  end
60
60
 
61
- def rails_files_controllers
62
- rails_files[:controllers]
61
+ def rails_resource_controllers
62
+ rails_resource[:controllers]
63
63
  end
64
64
 
65
65
  # Database Accessor/Helpers
@@ -13,7 +13,7 @@ module KDomain
13
13
  guard('indexes are missing') if database[:indexes].nil?
14
14
  guard('foreign keys are missing') if database[:foreign_keys].nil?
15
15
  guard('rails version is missing') if database[:meta][:rails].nil?
16
- guard('postgres extensions are missing') if database[:meta][:database][:extensions].nil?
16
+ guard('postgres extensions are missing') if database[:meta][:db_info][:extensions].nil?
17
17
  guard('unique keys are missing') if database[:meta][:unique_keys].nil?
18
18
  end
19
19
  end
@@ -13,7 +13,9 @@ class Step5AttachDictionary < KDomain::DomainModel::Step
13
13
  end
14
14
  end
15
15
 
16
- domain[:dictionary] = dictionary.values
16
+ domain_data[:dictionary] = {
17
+ items: dictionary.values
18
+ }
17
19
  end
18
20
 
19
21
  private
@@ -7,12 +7,14 @@ class Step8LocateRailsModels < KDomain::DomainModel::Step
7
7
  def call
8
8
  raise 'ERD path not supplied' if opts[:erd_path].nil?
9
9
 
10
- self.rails_files_models = domain_models.map { |model| locate_rails_model(model[:name], model[:table_name]) }
10
+ self.rails_resource_models = domain_models.map do |model|
11
+ locate_rails_model(model[:name], model[:table_name])
12
+ end
11
13
  end
12
14
 
13
15
  private
14
16
 
15
- def locate_rails_model(table_name, model_name)
17
+ def locate_rails_model(model_name, table_name)
16
18
  file_normal = File.join(opts[:erd_path], "#{model_name}.rb")
17
19
  file_custom = File.join(opts[:erd_path], "#{table_name}.rb")
18
20
  file_exist = true
@@ -16,7 +16,7 @@ module KDomain
16
16
 
17
17
  def initialize(source_file)
18
18
  @source_file = source_file
19
- @template_file = 'lib/k_domain/raw_db_schema/template.rb'
19
+ @template_file = KDomain::Gem.resource('templates/load_schema.rb')
20
20
  end
21
21
 
22
22
  def call
@@ -24,7 +24,6 @@ module KDomain
24
24
  # log.kv 'template_file', template_file
25
25
  # log.kv 'source_file?', File.exist?(source_file)
26
26
  # log.kv 'template_file?', File.exist?(template_file)
27
-
28
27
  log.error "Template not found: #{template_file}" unless File.exist?(template_file)
29
28
 
30
29
  content = File.read(source_file)
@@ -34,9 +33,9 @@ module KDomain
34
33
  lines = content.lines.map { |line| " #{line}" }.join
35
34
 
36
35
  @schema_loader = File
37
- .read(template_file)
38
- .gsub('{{source_file}}', source_file)
39
- .gsub('{{rails_schema}}', lines)
36
+ .read(template_file)
37
+ .gsub('{{source_file}}', source_file)
38
+ .gsub('{{rails_schema}}', lines)
40
39
  end
41
40
 
42
41
  # rename to target_ruby
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # log.warn 'models->domain' if AppDebug.require?
4
+
5
+ module Types
6
+ include Dry.Types()
7
+ end
8
+
9
+ require_relative 'rails_resource'
10
+ require_relative 'investigate'
11
+ require_relative 'database/_'
12
+ require_relative 'dictionary'
13
+ require_relative 'domain/_'
14
+
15
+ require_relative './domain_model'
@@ -1,14 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Types
4
- include Dry.Types()
5
- end
6
-
7
3
  # The require order is important due to dependencies
8
- require_relative './column'
9
- require_relative './database'
10
4
  require_relative './index'
11
5
  require_relative './table'
12
6
  require_relative './foreign_key'
13
- require_relative './unique_key'
14
7
  require_relative './schema'
@@ -3,10 +3,23 @@
3
3
  module KDomain
4
4
  module Database
5
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
+
6
19
  class Meta < Dry::Struct
7
20
  attribute :rails , Types::Strict::Integer
8
- attribute :database , KDomain::Database::Database
9
- attribute :unique_keys , Types::Strict::Array.of(KDomain::Database::UniqueKey)
21
+ attribute :db_info , KDomain::Database::Schema::DbInfo
22
+ attribute :unique_keys , Types::Strict::Array.of(KDomain::Database::Schema::UniqueKey)
10
23
  end
11
24
 
12
25
  attribute :tables , Types::Strict::Array.of(KDomain::Database::Table)
@@ -3,19 +3,30 @@
3
3
  module KDomain
4
4
  module Database
5
5
  class Table < Dry::Struct
6
- class Meta < Dry::Struct
6
+ class RailsSchema < Dry::Struct
7
7
  attribute :primary_key , Types::Nominal::Any.optional.default(nil)
8
8
  attribute :id , Types::Nominal::Any.optional.default(nil)
9
9
  attribute :force , Types::Nominal::Any.optional.default(nil)
10
10
  end
11
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
+
12
23
  attribute :name , Types::Strict::String
13
24
  attribute :primary_key , Types::Strict::String.optional.default(nil)
14
25
  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::Database::Column)
17
- attribute :indexes , Types::Strict::Array.of(KDomain::Database::Index)
18
- attribute :rails_schema , KDomain::Database::Table::Meta
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
19
30
  end
20
31
  end
21
32
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Domain class holds a dictionary entry
4
+ module KDomain
5
+ module Schemas
6
+ class Dictionary < Dry::Struct
7
+ attribute :items , Types::Strict::Array do
8
+ attribute :name , Types::Strict::String
9
+ attribute :type , Types::Strict::String
10
+ attribute :label , Types::Strict::String
11
+ attribute :segment , Types::Strict::String
12
+ attribute :models , Types::Strict::Array
13
+ attribute :model_count , Types::Strict::Integer
14
+ attribute :types , Types::Strict::Array
15
+ attribute :type_count , Types::Strict::Integer
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,13 +2,10 @@
2
2
 
3
3
  # log.warn 'models->domain' if AppDebug.require?
4
4
 
5
- require_relative './dictionary'
6
- require_relative './investigate'
7
5
  require_relative './models/column'
8
6
  require_relative './models/model'
9
7
  require_relative './erd_file'
10
8
  require_relative './domain'
11
- require_relative './schema'
12
9
 
13
10
  module KDomain
14
11
  module DomainModel
@@ -6,7 +6,6 @@ module KDomain
6
6
  class Domain < Dry::Struct
7
7
  attribute :models , Types::Strict::Array.of(KDomain::DomainModel::Model)
8
8
  attribute :erd_files , Types::Strict::Array.of(KDomain::DomainModel::ErdFile)
9
- attribute :dictionary , Types::Strict::Array.of(KDomain::DomainModel::Dictionary)
10
9
  end
11
10
  end
12
11
  end
@@ -2,12 +2,13 @@
2
2
 
3
3
  # DomainModel holds the entire domain model including database and ancillary information
4
4
  module KDomain
5
- module DomainModel
6
- class Schema < Dry::Struct
5
+ module Schemas
6
+ class DomainModel < Dry::Struct
7
7
  attribute :domain , KDomain::DomainModel::Domain
8
8
  attribute :database , KDomain::Database::Schema
9
- # attribute :rails_files , KDomain::RailsFiles::Schema
10
- attribute :investigate , KDomain::DomainModel::Investigate
9
+ attribute :dictionary , KDomain::Schemas::Dictionary
10
+ attribute :rails_resource , KDomain::Schemas::RailsResource
11
+ attribute :investigate , KDomain::Schemas::Investigate
11
12
  end
12
13
  end
13
14
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Domain class holds a dictionary entry
4
4
  module KDomain
5
- module DomainModel
5
+ module Schemas
6
6
  class Investigate < Dry::Struct
7
7
  attribute :issues , Types::Strict::Array do
8
8
  attribute :step , Types::Strict::String
@@ -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.11'
4
+ VERSION = '0.0.14'
5
5
  end
data/lib/k_domain.rb CHANGED
@@ -5,9 +5,7 @@ require 'dry-struct'
5
5
  require 'k_log'
6
6
  require 'peeky'
7
7
  require 'k_domain/version'
8
- require 'k_domain/schemas/database/_'
9
- require 'k_domain/schemas/domain/_'
10
-
8
+ require 'k_domain/schemas/_'
11
9
  require 'k_domain/raw_db_schema/transform'
12
10
  require 'k_domain/raw_db_schema/load'
13
11
  require 'k_domain/domain_model/transform'
@@ -23,6 +21,15 @@ module KDomain
23
21
  # raise KDomain::Error, 'Sample message'
24
22
  class Error < StandardError; end
25
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
+
26
33
  # Your code goes here...
27
34
  end
28
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.14
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-10-01 00:00:00.000000000 Z
11
+ date: 2021-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -106,21 +106,17 @@ files:
106
106
  - lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb
107
107
  - lib/k_domain/domain_model/transform_steps/step8_locate_rails_models.rb
108
108
  - lib/k_domain/raw_db_schema/load.rb
109
- - lib/k_domain/raw_db_schema/template.rb
110
109
  - lib/k_domain/raw_db_schema/transform.rb
110
+ - lib/k_domain/schemas/_.rb
111
111
  - lib/k_domain/schemas/database/_.rb
112
- - lib/k_domain/schemas/database/column.rb
113
- - lib/k_domain/schemas/database/database.rb
114
112
  - lib/k_domain/schemas/database/foreign_key.rb
115
113
  - lib/k_domain/schemas/database/index.rb
116
114
  - lib/k_domain/schemas/database/schema.rb
117
115
  - lib/k_domain/schemas/database/table.rb
118
- - lib/k_domain/schemas/database/unique_key.rb
116
+ - lib/k_domain/schemas/dictionary.rb
119
117
  - lib/k_domain/schemas/domain/_.rb
120
- - lib/k_domain/schemas/domain/dictionary.rb
121
118
  - lib/k_domain/schemas/domain/domain.rb
122
119
  - lib/k_domain/schemas/domain/erd_file.rb
123
- - lib/k_domain/schemas/domain/investigate.rb
124
120
  - lib/k_domain/schemas/domain/models/column.rb
125
121
  - lib/k_domain/schemas/domain/models/model.rb
126
122
  - lib/k_domain/schemas/domain/old/belongs_to.rb
@@ -139,8 +135,11 @@ files:
139
135
  - lib/k_domain/schemas/domain/old/statistics.rb
140
136
  - lib/k_domain/schemas/domain/old/validate.rb
141
137
  - lib/k_domain/schemas/domain/old/validates.rb
142
- - lib/k_domain/schemas/domain/schema.rb
138
+ - lib/k_domain/schemas/domain_model.rb
139
+ - lib/k_domain/schemas/investigate.rb
140
+ - lib/k_domain/schemas/rails_resource.rb
143
141
  - lib/k_domain/version.rb
142
+ - templates/load_schema.rb
144
143
  homepage: http://appydave.com/gems/k-domain
145
144
  licenses:
146
145
  - MIT
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDomain
4
- module Database
5
- class Column < Dry::Struct
6
- attribute :name , Types::Strict::String
7
- attribute :type , Types::Strict::String
8
- attribute :precision? , Types::Strict::Integer.optional.default(nil)
9
- attribute :scale? , Types::Strict::Integer.optional.default(nil)
10
- attribute :default? , Types::Nominal::Any.optional.default(nil) # Types::Strict::Bool.optional.default(nil) | Types::Strict::Integer.optional.default(nil)
11
- attribute :array? , Types::Strict::Bool.optional.default(nil)
12
- attribute :null? , Types::Strict::Bool.optional.default(nil)
13
- attribute :limit? , Types::Strict::Integer.optional.default(nil)
14
- end
15
- end
16
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDomain
4
- module Database
5
- class Database < Dry::Struct
6
- attribute :type , Types::Strict::String
7
- attribute :version , Types::Nominal::Any.optional.default(nil)
8
- attribute :extensions , Types::Strict::Array
9
- end
10
- end
11
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDomain
4
- module Database
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
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Domain class holds a dictionary entry
4
- module KDomain
5
- module DomainModel
6
- class Dictionary < Dry::Struct
7
- attribute :name , Types::Strict::String
8
- attribute :type , Types::Strict::String
9
- attribute :label , Types::Strict::String
10
- attribute :segment , Types::Strict::String
11
- attribute :models , Types::Strict::Array
12
- attribute :model_count , Types::Strict::Integer
13
- attribute :types , Types::Strict::Array
14
- attribute :type_count , Types::Strict::Integer
15
- end
16
- end
17
- end