k_domain 0.0.20 → 0.0.27
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/.github/workflows/main.yml +5 -3
- data/.gitignore +2 -0
- data/.rubocop.yml +9 -5
- data/Gemfile +1 -1
- data/Guardfile +1 -0
- data/README.md +15 -0
- data/k_domain.gemspec +1 -1
- 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/build_rich_models.rb +64 -0
- data/lib/k_domain/domain_model/load.rb +44 -1
- data/lib/k_domain/domain_model/transform.rb +28 -16
- data/lib/k_domain/domain_model/transform_steps/_.rb +7 -5
- data/lib/k_domain/domain_model/transform_steps/step.rb +20 -0
- 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/{step6_attach_dictionary.rb → step20_dictionary.rb} +6 -6
- data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +123 -0
- data/lib/k_domain/domain_model/transform_steps/step4_rails_resource_models.rb +3 -3
- 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 +91 -0
- data/lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb +114 -0
- data/lib/k_domain/domain_model/transform_steps/step8_domain_columns.rb +99 -0
- data/lib/k_domain/queries/_.rb +4 -0
- data/lib/k_domain/queries/base_query.rb +13 -0
- data/lib/k_domain/queries/domain_model_query.rb +88 -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 +21 -8
- data/lib/k_domain/rails_code_extractor/shim_loader.rb +4 -1
- 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 +5 -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 +153 -0
- data/lib/k_domain/schemas/{domain/_.rb → domain_types.rb} +1 -8
- data/lib/k_domain/schemas/{domain_model.rb → main_dataset.rb} +4 -4
- data/lib/k_domain/schemas/rails_resource.rb +43 -6
- data/lib/k_domain/schemas/rails_structure.rb +104 -14
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +7 -3
- data/templates/custom/action_controller.rb +7 -0
- data/templates/custom/controller_interceptors.rb +80 -0
- data/templates/custom/model_interceptors.rb +95 -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} +23 -41
- 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 +36 -21
- 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/step5_rails_models.rb +0 -71
- 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
@@ -8,26 +8,26 @@ module KDomain
|
|
8
8
|
attribute :block? , Types::Strict::String
|
9
9
|
end
|
10
10
|
|
11
|
-
class
|
12
|
-
attribute :name? , Types::Strict::String
|
11
|
+
class NameOptsType < Dry::Struct
|
12
|
+
attribute :name? , Types::Strict::String | Types::Strict::Bool
|
13
13
|
attribute :opts? , Types::Strict::Hash
|
14
14
|
attribute :block? , Types::Strict::String.optional.default(nil)
|
15
15
|
end
|
16
16
|
|
17
|
-
class
|
17
|
+
class OptsType < Dry::Struct
|
18
|
+
attribute :opts? , Types::Strict::Hash
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
end
|
21
|
+
# Model Behaviours
|
22
|
+
class Scope < KDomain::Schemas::RailsStructure::NameOptsType; end
|
22
23
|
|
23
|
-
class
|
24
|
-
end
|
24
|
+
class BelongsTo < KDomain::Schemas::RailsStructure::NameOptsType; end
|
25
25
|
|
26
|
-
class
|
27
|
-
end
|
26
|
+
class HasOne < KDomain::Schemas::RailsStructure::NameOptsType; end
|
28
27
|
|
29
|
-
class
|
30
|
-
|
28
|
+
class HasMany < KDomain::Schemas::RailsStructure::NameOptsType; end
|
29
|
+
|
30
|
+
class HasAndBelongsToMany < KDomain::Schemas::RailsStructure::NameOptsType; end
|
31
31
|
|
32
32
|
class Validate < Dry::Struct
|
33
33
|
attribute :names? , Types::Array.of(Types::Strict::String)
|
@@ -35,10 +35,10 @@ module KDomain
|
|
35
35
|
attribute :block? , Types::Strict::String.optional.default(nil)
|
36
36
|
end
|
37
37
|
|
38
|
-
class Validates < KDomain::Schemas::RailsStructure::
|
38
|
+
class Validates < KDomain::Schemas::RailsStructure::NameOptsType
|
39
39
|
end
|
40
40
|
|
41
|
-
class
|
41
|
+
class ModelBehaviours < Dry::Struct
|
42
42
|
attribute :class_name? , Types::Strict::String
|
43
43
|
attribute :default_scope? , KDomain::Schemas::RailsStructure::DefaultScope
|
44
44
|
attribute :scopes? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Scope)
|
@@ -51,6 +51,16 @@ module KDomain
|
|
51
51
|
attribute :attr_accessor? , Types::Array.of(Types::Strict::String)
|
52
52
|
attribute :attr_reader? , Types::Array.of(Types::Strict::String)
|
53
53
|
attribute :attr_writer? , Types::Array.of(Types::Strict::String)
|
54
|
+
|
55
|
+
# Not sure if I need to do a behaviours by column names
|
56
|
+
# def belongs_to_by(foreign_key: )
|
57
|
+
# end
|
58
|
+
# def has_one_by(foreign_key: )
|
59
|
+
# end
|
60
|
+
# def has_many_by(foreign_key: )
|
61
|
+
# end
|
62
|
+
# def has_and_belongs_to_many_to_by(foreign_key: )
|
63
|
+
# end
|
54
64
|
end
|
55
65
|
|
56
66
|
class Method < Dry::Struct
|
@@ -76,15 +86,95 @@ module KDomain
|
|
76
86
|
attribute :exist , Types::Strict::Bool
|
77
87
|
attribute :state , Types::Strict::String
|
78
88
|
attribute :code , Types::Strict::String
|
79
|
-
attribute :behaviours? , KDomain::Schemas::RailsStructure::
|
89
|
+
attribute :behaviours? , KDomain::Schemas::RailsStructure::ModelBehaviours
|
80
90
|
attribute :functions? , KDomain::Schemas::RailsStructure::Functions
|
81
91
|
end
|
82
92
|
|
93
|
+
# Controller Behaviours
|
94
|
+
class AfterAction < KDomain::Schemas::RailsStructure::NameOptsType; end
|
95
|
+
|
96
|
+
class AroundAction < KDomain::Schemas::RailsStructure::NameOptsType; end
|
97
|
+
|
98
|
+
class BeforeAction < KDomain::Schemas::RailsStructure::NameOptsType; end
|
99
|
+
|
100
|
+
# rubocop:disable Naming/ClassAndModuleCamelCase
|
101
|
+
class Prepend_beforeAction < KDomain::Schemas::RailsStructure::NameOptsType; end
|
102
|
+
|
103
|
+
class Skip_beforeAction < KDomain::Schemas::RailsStructure::NameOptsType; end
|
104
|
+
# rubocop:enable Naming/ClassAndModuleCamelCase
|
105
|
+
|
106
|
+
class BeforeFilter < KDomain::Schemas::RailsStructure::NameOptsType; end
|
107
|
+
|
108
|
+
class SkipBeforeFilter < KDomain::Schemas::RailsStructure::NameOptsType; end
|
109
|
+
|
110
|
+
class Layout < KDomain::Schemas::RailsStructure::NameOptsType; end
|
111
|
+
|
112
|
+
class HttpBasicAuthenticateWith < KDomain::Schemas::RailsStructure::OptsType; end
|
113
|
+
|
114
|
+
class ProtectFromForgery < KDomain::Schemas::RailsStructure::OptsType; end
|
115
|
+
|
116
|
+
class RescueFrom < Dry::Struct
|
117
|
+
attribute :type , Types::Strict::String
|
118
|
+
end
|
119
|
+
|
120
|
+
class HelperMethod < Dry::Struct
|
121
|
+
attribute :names , Types::Strict::Array.of(Types::Strict::String)
|
122
|
+
end
|
123
|
+
|
124
|
+
class Helper < Dry::Struct
|
125
|
+
attribute :name , Types::Strict::String
|
126
|
+
end
|
127
|
+
|
128
|
+
class ControllerBehaviours < Dry::Struct
|
129
|
+
attribute :class_name? , Types::Strict::String
|
130
|
+
attribute :after_action? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::AfterAction)
|
131
|
+
attribute :around_action? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::AroundAction)
|
132
|
+
attribute :before_action? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::BeforeAction)
|
133
|
+
attribute :prepend_before_action? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Prepend_beforeAction)
|
134
|
+
attribute :skip_before_action? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Skip_beforeAction)
|
135
|
+
attribute :before_filter? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::BeforeFilter)
|
136
|
+
attribute :skip_before_filter? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::SkipBeforeFilter)
|
137
|
+
attribute :layout? , KDomain::Schemas::RailsStructure::Layout
|
138
|
+
attribute :http_basic_authenticate_with? , KDomain::Schemas::RailsStructure::OptsType
|
139
|
+
attribute :protect_from_forgery? , KDomain::Schemas::RailsStructure::OptsType
|
140
|
+
|
141
|
+
attribute :rescue_from? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::RescueFrom)
|
142
|
+
attribute :helper_method? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::HelperMethod)
|
143
|
+
attribute :helper? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Helper)
|
144
|
+
end
|
145
|
+
|
146
|
+
class ControllerActions < Dry::Struct
|
147
|
+
attribute :route_name? , Types::Strict::String
|
148
|
+
attribute :action? , Types::String.optional
|
149
|
+
attribute :uri_path? , Types::String
|
150
|
+
attribute :mime_match? , Types::String
|
151
|
+
attribute :verbs? , Types.Array(Types::Verb)
|
152
|
+
end
|
153
|
+
|
83
154
|
class Controller < Dry::Struct
|
155
|
+
attribute :name , Types::String
|
156
|
+
attribute :path , Types::String
|
157
|
+
attribute :namespace , Types::String
|
158
|
+
attribute :file , Types::String
|
159
|
+
attribute :exist , Types::Bool
|
160
|
+
attribute :full_file , Types::String
|
161
|
+
attribute :behaviours? , KDomain::Schemas::RailsStructure::ControllerBehaviours
|
162
|
+
attribute :functions? , KDomain::Schemas::RailsStructure::Functions
|
163
|
+
attribute :actions? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::ControllerActions)
|
84
164
|
end
|
85
165
|
|
86
166
|
attribute :models , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Model)
|
87
167
|
attribute :controllers , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Controller)
|
168
|
+
|
169
|
+
def find_controller(path)
|
170
|
+
path = path.to_s
|
171
|
+
controllers.find { |controller| controller.path.to_s == path }
|
172
|
+
end
|
173
|
+
|
174
|
+
def find_model(name)
|
175
|
+
name = name.to_s
|
176
|
+
models.find { |model| model.model_name.to_s == name }
|
177
|
+
end
|
88
178
|
end
|
89
179
|
end
|
90
180
|
end
|
data/lib/k_domain/version.rb
CHANGED
data/lib/k_domain.rb
CHANGED
@@ -5,14 +5,16 @@ require 'dry-struct'
|
|
5
5
|
require 'k_log'
|
6
6
|
require 'peeky'
|
7
7
|
require 'k_domain/version'
|
8
|
+
require 'k_domain/config/_'
|
8
9
|
require 'k_domain/schemas/_'
|
9
10
|
require 'k_domain/raw_db_schema/transform'
|
10
11
|
require 'k_domain/raw_db_schema/load'
|
11
12
|
require 'k_domain/domain_model/transform'
|
12
13
|
require 'k_domain/domain_model/transform_steps/_'
|
13
14
|
require 'k_domain/domain_model/load'
|
14
|
-
require 'k_domain/
|
15
|
-
require 'k_domain/rails_code_extractor/
|
15
|
+
require 'k_domain/domain_model/build_rich_models'
|
16
|
+
require 'k_domain/rails_code_extractor/_'
|
17
|
+
require 'k_domain/queries/_'
|
16
18
|
|
17
19
|
# # This is useful if you want to initialize structures via Hash
|
18
20
|
# class SymbolizeStruct < Dry::Struct
|
@@ -20,6 +22,8 @@ require 'k_domain/rails_code_extractor/extract_model'
|
|
20
22
|
# end
|
21
23
|
|
22
24
|
module KDomain
|
25
|
+
extend KDomain::Config
|
26
|
+
|
23
27
|
# raise KDomain::Error, 'Sample message'
|
24
28
|
class Error < StandardError; end
|
25
29
|
|
@@ -36,7 +40,7 @@ module KDomain
|
|
36
40
|
# Your code goes here...
|
37
41
|
end
|
38
42
|
|
39
|
-
if ENV
|
43
|
+
if ENV.fetch('KLUE_DEBUG', 'false').downcase == 'true'
|
40
44
|
namespace = 'KDomain::Version'
|
41
45
|
file_path = $LOADED_FEATURES.find { |f| f.include?('k_domain/version') }
|
42
46
|
version = KDomain::VERSION.ljust(9)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class Rails
|
2
|
+
def self.env; end
|
3
|
+
|
4
|
+
def self.application
|
5
|
+
OpenStruct.new(
|
6
|
+
secrets: OpenStruct.new(
|
7
|
+
credentials_secret_key: Base64.encode64('ABC'),
|
8
|
+
aws_secret_access_key: Base64.encode64('ABC')
|
9
|
+
)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class ApplicationController < ActionController::Base
|
14
|
+
def self.require(*_p, **_o); end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Admin
|
18
|
+
class BaseController < ActionController::Base
|
19
|
+
end
|
20
|
+
end
|
21
|
+
module Api
|
22
|
+
module V1
|
23
|
+
class BaseController < ActionController::Base
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Enterprises
|
29
|
+
class BaseController < ActionController::Base
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Portal
|
34
|
+
class BaseController < ApplicationController
|
35
|
+
end
|
36
|
+
end
|
37
|
+
module ActiveRecord
|
38
|
+
class RecordNotFound
|
39
|
+
end
|
40
|
+
end
|
41
|
+
class RegionConfig < ActiveRecord::Base
|
42
|
+
def self.require_value(*_p, **_o, &block)
|
43
|
+
return 'ABC'
|
44
|
+
end
|
45
|
+
def self.get_value
|
46
|
+
return 'ABC'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
module Aws
|
50
|
+
class Credentials
|
51
|
+
def initialize(*_p, **_o, &block); end
|
52
|
+
end
|
53
|
+
module S3
|
54
|
+
class Client
|
55
|
+
def initialize(*_p, **_o, &block); end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module Devise
|
61
|
+
class SessionsController < ActionController::Base
|
62
|
+
end
|
63
|
+
class Mapping
|
64
|
+
def self.find_scope!(*_p, **_o); end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
module Respondable; end
|
69
|
+
module ContactUpdateable; end
|
70
|
+
module SalesRepUpdateable; end
|
71
|
+
module MIME; end
|
72
|
+
module MaterialIconsHelper; end
|
73
|
+
module LocationUpdateable; end
|
74
|
+
module WantedByUpdateable; end
|
75
|
+
module FollowUpUpdateable; end
|
76
|
+
module EstimateArchiveUpdateable; end
|
77
|
+
module ContextContactUpdateable; end
|
78
|
+
module ProofDateUpdateable; end
|
79
|
+
module PoUpdateable; end
|
80
|
+
module SalesRepUpdateable; end
|
@@ -0,0 +1,95 @@
|
|
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
|
+
class Thread
|
20
|
+
def initialize(*_p, **_o, &block); end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ApplicationRecord < ActiveRecord::Base
|
24
|
+
end
|
25
|
+
|
26
|
+
class Email < ActiveRecord::Base
|
27
|
+
def self.ses_send(*_p, **_o); end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Emails
|
31
|
+
class Task
|
32
|
+
def new_task(*_p, **_o); end
|
33
|
+
end
|
34
|
+
class Salesrep
|
35
|
+
def change_sales_rep(*_p, **_o); end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module EstimateConvertable; end
|
40
|
+
module ApiLoggable; end
|
41
|
+
module Excludable; end
|
42
|
+
module Bookmarkable; end
|
43
|
+
module Categorizable; end
|
44
|
+
module PgSearch
|
45
|
+
module Model
|
46
|
+
end
|
47
|
+
end
|
48
|
+
module Excludable; end
|
49
|
+
module JsonbStore
|
50
|
+
def self.included(klass)
|
51
|
+
klass.extend(ClassMethods)
|
52
|
+
end
|
53
|
+
|
54
|
+
module ClassMethods
|
55
|
+
def jsonb_store(*_p, **_o); end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
module ActionView
|
59
|
+
module Helpers
|
60
|
+
module NumberHelper
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
module PrintSpeak
|
65
|
+
class Application
|
66
|
+
def self.google_oath_secret_key
|
67
|
+
'ABC'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
class RegionConfig < ActiveRecord::Base
|
72
|
+
def self.require_value(*_p, **_o, &block)
|
73
|
+
'ABC'
|
74
|
+
end
|
75
|
+
def self.get_value
|
76
|
+
return 'ABC'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
module RailsUpgrade
|
80
|
+
def rails4?
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
def rails5?
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
def rails6?
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
def belongs_to_required
|
93
|
+
{}
|
94
|
+
end
|
95
|
+
end
|
data/templates/load_schema.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class LoadSchema
|
2
2
|
attr_reader :schema
|
3
3
|
|
4
|
+
# XMEN
|
4
5
|
def initialize
|
5
6
|
@unique_keys = {}
|
6
7
|
@current_table = nil
|
@@ -9,6 +10,7 @@ class LoadSchema
|
|
9
10
|
tables: [],
|
10
11
|
foreign_keys: [],
|
11
12
|
indexes: [],
|
13
|
+
views: [],
|
12
14
|
meta: {
|
13
15
|
rails: @rails_version,
|
14
16
|
db_info: {
|
@@ -131,6 +133,11 @@ class LoadSchema
|
|
131
133
|
add_index(name, fields, **opts)
|
132
134
|
end
|
133
135
|
|
136
|
+
def create_view(name, **opts)
|
137
|
+
row = { name: name, **opts }
|
138
|
+
schema[:views] << row
|
139
|
+
add_unique_keys(row.keys, type: :views)
|
140
|
+
end
|
134
141
|
|
135
142
|
def add_foreign_key(left_table, right_table, **opts)
|
136
143
|
# puts "add_foreign_key(#{left_table}, #{right_table})"
|