k_domain 0.0.15 → 0.0.16
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 +4 -4
- data/.rubocop.yml +3 -1
- data/Gemfile +1 -1
- data/k_domain.gemspec +1 -1
- data/lib/k_domain/domain_model/transform.rb +19 -8
- data/lib/k_domain/domain_model/transform_steps/_.rb +2 -1
- data/lib/k_domain/domain_model/transform_steps/step.rb +20 -1
- data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +2 -1
- data/lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb +2 -1
- data/lib/k_domain/domain_model/transform_steps/{step8_locate_rails_models.rb → step8_rails_resource_models.rb} +1 -1
- data/lib/k_domain/domain_model/transform_steps/step9_rails_structure_models.rb +33 -0
- data/lib/k_domain/rails_code_extractor/extract_model.rb +21 -0
- data/lib/k_domain/rails_code_extractor/load_shim.rb +32 -0
- data/lib/k_domain/raw_db_schema/transform.rb +7 -7
- data/lib/k_domain/schemas/database/schema.rb +1 -1
- data/lib/k_domain/schemas/database/table.rb +1 -1
- data/lib/k_domain/schemas/domain/erd_file.rb +2 -0
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +3 -0
- data/templates/active_record_shims.rb +355 -0
- data/templates/fake_module_shims.rb +42 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98e1d3eb1435f17ad91084519399234f0adc41e399d1350071147f0e58f694c6
|
4
|
+
data.tar.gz: 2797a698e87169816a6b612239b1c22b8d2fd0db2fd6df2fc8e078fbf8828e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6cd0d3fa8354f83b5910dc961212acd0ae149b0b90c31338bf992b4f64500ae4fb05f63c605bf439d818bed8f6f4806939994c0cf8ee6fbd0c0a51d232b02f
|
7
|
+
data.tar.gz: 28d42c273b6fdae5db9b32e4cfcd4c1826e42f929efbc9713941b16bc4240cff22eed7e3260aec195beff43ae3ec20bf136bb6526988eccbd5f475c18ec2566a
|
data/.rubocop.yml
CHANGED
@@ -8,7 +8,9 @@ AllCops:
|
|
8
8
|
- "_/**/*"
|
9
9
|
- "spec/sample_input/**/*"
|
10
10
|
- "spec/sample_output/**/*"
|
11
|
-
- "
|
11
|
+
- "templates/**/*"
|
12
|
+
- "lib/k_domain/schemas/domain/old/**/*"
|
13
|
+
- "spec/k_domain/ruby_loader/**/*"
|
12
14
|
|
13
15
|
Metrics/PerceivedComplexity:
|
14
16
|
Exclude:
|
data/Gemfile
CHANGED
@@ -28,8 +28,8 @@ end
|
|
28
28
|
if ENV['KLUE_LOCAL_GEMS']&.to_s&.downcase == 'true'
|
29
29
|
group :development, :test do
|
30
30
|
puts 'Using Local GEMs'
|
31
|
-
gem 'peeky' , path: '../peeky'
|
32
31
|
gem 'k_log' , path: '../k_log'
|
33
32
|
gem 'k_util' , path: '../k_util'
|
33
|
+
gem 'peeky' , path: '../peeky'
|
34
34
|
end
|
35
35
|
end
|
data/k_domain.gemspec
CHANGED
@@ -20,6 +20,7 @@ module KDomain
|
|
20
20
|
@erd_path = erd_path
|
21
21
|
end
|
22
22
|
|
23
|
+
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
23
24
|
def call
|
24
25
|
valid = true
|
25
26
|
valid &&= step1
|
@@ -27,7 +28,8 @@ module KDomain
|
|
27
28
|
valid &&= step3
|
28
29
|
valid &&= step4
|
29
30
|
valid &&= step5
|
30
|
-
valid &&= step8
|
31
|
+
valid &&= step8
|
32
|
+
valid &&= step9
|
31
33
|
|
32
34
|
raise 'DomainModal transform failed' unless valid
|
33
35
|
|
@@ -35,6 +37,7 @@ module KDomain
|
|
35
37
|
|
36
38
|
nil
|
37
39
|
end
|
40
|
+
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
38
41
|
|
39
42
|
def step1
|
40
43
|
Step1AttachDbSchema.run(domain_data, db_schema: db_schema)
|
@@ -62,8 +65,13 @@ module KDomain
|
|
62
65
|
end
|
63
66
|
|
64
67
|
def step8
|
65
|
-
|
66
|
-
write(step: '8-rails-
|
68
|
+
Step8RailsResourceModels.run(domain_data, erd_path: erd_path)
|
69
|
+
write(step: '8-rails-resource-models')
|
70
|
+
end
|
71
|
+
|
72
|
+
def step9
|
73
|
+
Step9RailsStructureModels.run(domain_data, erd_path: erd_path)
|
74
|
+
write(step: '8-rails-structure-models')
|
67
75
|
end
|
68
76
|
|
69
77
|
def write(step: nil)
|
@@ -76,20 +84,21 @@ module KDomain
|
|
76
84
|
File.write(file, JSON.pretty_generate(domain_data))
|
77
85
|
end
|
78
86
|
|
87
|
+
# rubocop:disable Metrics/MethodLength
|
79
88
|
def domain_data
|
80
89
|
# The initial domain model structure is created here, but populated during the workflows.
|
81
90
|
@domain_data ||= {
|
82
91
|
domain: {
|
83
92
|
models: [],
|
84
|
-
erd_files: []
|
93
|
+
erd_files: []
|
85
94
|
},
|
86
|
-
|
95
|
+
rails_resource: {
|
87
96
|
models: [],
|
88
|
-
controllers: []
|
97
|
+
controllers: []
|
89
98
|
},
|
90
|
-
|
99
|
+
rails_structure: {
|
91
100
|
models: [],
|
92
|
-
controllers: []
|
101
|
+
controllers: []
|
93
102
|
},
|
94
103
|
dictionary: {
|
95
104
|
items: []
|
@@ -105,6 +114,8 @@ module KDomain
|
|
105
114
|
}
|
106
115
|
}
|
107
116
|
end
|
117
|
+
|
118
|
+
# rubocop:enable Metrics/MethodLength
|
108
119
|
end
|
109
120
|
end
|
110
121
|
end
|
@@ -7,4 +7,5 @@ require_relative './step2_attach_models'
|
|
7
7
|
require_relative './step3_attach_columns'
|
8
8
|
require_relative './step4_attach_erd_files'
|
9
9
|
require_relative './step5_attach_dictionary'
|
10
|
-
require_relative './
|
10
|
+
require_relative './step8_rails_resource_models'
|
11
|
+
require_relative './step9_rails_structure_models'
|
@@ -43,7 +43,7 @@ module KDomain
|
|
43
43
|
domain[:models]
|
44
44
|
end
|
45
45
|
|
46
|
-
# Rails File Accessor/Helpers
|
46
|
+
# Rails Resource File Accessor/Helpers
|
47
47
|
def rails_resource
|
48
48
|
guard('rails_resource is missing') if domain_data[:rails_resource].nil?
|
49
49
|
|
@@ -62,6 +62,25 @@ module KDomain
|
|
62
62
|
rails_resource[:controllers]
|
63
63
|
end
|
64
64
|
|
65
|
+
# Rails Structure File Accessor/Helpers
|
66
|
+
def rails_structure
|
67
|
+
guard('rails_structure is missing') if domain_data[:rails_structure].nil?
|
68
|
+
|
69
|
+
domain_data[:rails_structure]
|
70
|
+
end
|
71
|
+
|
72
|
+
def rails_structure_models
|
73
|
+
rails_structure[:models]
|
74
|
+
end
|
75
|
+
|
76
|
+
def rails_structure_models=(value)
|
77
|
+
rails_structure[:models] = value
|
78
|
+
end
|
79
|
+
|
80
|
+
def rails_structure_controllers
|
81
|
+
rails_structure[:controllers]
|
82
|
+
end
|
83
|
+
|
65
84
|
# Database Accessor/Helpers
|
66
85
|
def database=(value)
|
67
86
|
domain_data[:database] = value
|
@@ -27,7 +27,8 @@ class Step5AttachDictionary < KDomain::DomainModel::Step
|
|
27
27
|
entry[:model_count] = entry[:model_count] + 1
|
28
28
|
|
29
29
|
unless entry[:types].include?(column_type)
|
30
|
-
|
30
|
+
# ADD to investigate
|
31
|
+
# log.warn("#{model_name} has a type mismatch for column name: #{column_name}")
|
31
32
|
entry[:types] << column_type
|
32
33
|
entry[:type_count] = entry[:type_count] + 1
|
33
34
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Locate rails model files
|
4
|
+
class Step9RailsStructureModels < KDomain::DomainModel::Step
|
5
|
+
attr_accessor :ruby_code
|
6
|
+
|
7
|
+
def call
|
8
|
+
raise 'ERD path not supplied' if opts[:erd_path].nil?
|
9
|
+
|
10
|
+
self.rails_structure_models = rails_resource_models.map do |resource|
|
11
|
+
process_resource(OpenStruct.new(resource))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def process_resource(resource)
|
18
|
+
erd_path = opts[:erd_path]
|
19
|
+
puts erd_path
|
20
|
+
@model = {
|
21
|
+
model_name: resource.model_name,
|
22
|
+
table_name: resource.table_name,
|
23
|
+
file: resource.file,
|
24
|
+
exist: resource.exist,
|
25
|
+
state: resource.state,
|
26
|
+
code: resource.exist ? File.read(resource.file) : '',
|
27
|
+
behaviours: {},
|
28
|
+
functions: {}
|
29
|
+
}
|
30
|
+
|
31
|
+
@model
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Takes a Rails Model and extracts DSL behaviours and custom functions (instance, class and private methods)
|
4
|
+
module KDomain
|
5
|
+
module RailsCodeExtractor
|
6
|
+
class ExtractModel
|
7
|
+
include KLog::Logging
|
8
|
+
|
9
|
+
attr_reader :source_file
|
10
|
+
attr_reader :data
|
11
|
+
|
12
|
+
def initialize(source_file)
|
13
|
+
@source_file = source_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
log.kv 'source_file', source_file
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Code extraction requires shims to be loaded before extraction
|
4
|
+
#
|
5
|
+
# This shims server two purposes
|
6
|
+
#
|
7
|
+
# 1. Inject data capture methods calls that intercept DSL macros so that data can be extracted
|
8
|
+
# 2. Inject fake module/classes that would otherwise break code loading with various exceptions
|
9
|
+
module KDomain
|
10
|
+
module RailsCodeExtractor
|
11
|
+
class LoadShim
|
12
|
+
include KLog::Logging
|
13
|
+
|
14
|
+
attr_reader :shim_files
|
15
|
+
|
16
|
+
attr_reader :dsl_shim_file
|
17
|
+
attr_reader :fake_module_file
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@shim_files = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
log.kv 'preload', preload
|
25
|
+
end
|
26
|
+
|
27
|
+
def register(name, file)
|
28
|
+
@shim_files << { name: name, file: file, exist: File.exist?(file) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -33,9 +33,9 @@ module KDomain
|
|
33
33
|
lines = content.lines.map { |line| " #{line}" }.join
|
34
34
|
|
35
35
|
@schema_loader = File
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
.read(template_file)
|
37
|
+
.gsub('{{source_file}}', source_file)
|
38
|
+
.gsub('{{rails_schema}}', lines)
|
39
39
|
end
|
40
40
|
|
41
41
|
# rename to target_ruby
|
@@ -68,13 +68,13 @@ module KDomain
|
|
68
68
|
return
|
69
69
|
end
|
70
70
|
|
71
|
-
eval(schema_loader)
|
71
|
+
eval(schema_loader) # , __FILE__, __LINE__)
|
72
72
|
|
73
73
|
loader = LoadSchema.new
|
74
74
|
loader.load_schema
|
75
|
-
|
76
|
-
rescue =>
|
77
|
-
log.exception(
|
75
|
+
loader.schema
|
76
|
+
rescue StandardError => e
|
77
|
+
log.exception(e)
|
78
78
|
end
|
79
79
|
# rubocop:enable Security/Eval
|
80
80
|
end
|
@@ -19,7 +19,7 @@ module KDomain
|
|
19
19
|
attribute :null? , Types::Strict::Bool.optional.default(nil)
|
20
20
|
attribute :limit? , Types::Strict::Integer.optional.default(nil)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
attribute :name , Types::Strict::String
|
24
24
|
attribute :primary_key , Types::Strict::String.optional.default(nil)
|
25
25
|
attribute :primary_key_type , Types::Strict::String.optional.default(nil)
|
@@ -3,6 +3,7 @@
|
|
3
3
|
# Domain class holds a list of the entities
|
4
4
|
module KDomain
|
5
5
|
module DomainModel
|
6
|
+
# rubocop:disable Metrics/BlockLength
|
6
7
|
class ErdFile < Dry::Struct
|
7
8
|
attribute :name , Types::Strict::String
|
8
9
|
attribute :name_plural , Types::Strict::String
|
@@ -76,5 +77,6 @@ module KDomain
|
|
76
77
|
end
|
77
78
|
end
|
78
79
|
end
|
80
|
+
# rubocop:enable Metrics/BlockLength
|
79
81
|
end
|
80
82
|
end
|
data/lib/k_domain/version.rb
CHANGED
data/lib/k_domain.rb
CHANGED
@@ -11,6 +11,8 @@ require 'k_domain/raw_db_schema/load'
|
|
11
11
|
require 'k_domain/domain_model/transform'
|
12
12
|
require 'k_domain/domain_model/transform_steps/_'
|
13
13
|
require 'k_domain/domain_model/load'
|
14
|
+
require 'k_domain/rails_code_extractor/load_shim'
|
15
|
+
# require 'k_domain/rails_code_extractor/extract_model'
|
14
16
|
|
15
17
|
# # This is useful if you want to initialize structures via Hash
|
16
18
|
# class SymbolizeStruct < Dry::Struct
|
@@ -25,6 +27,7 @@ module KDomain
|
|
25
27
|
def self.root
|
26
28
|
File.expand_path('..', File.dirname(__FILE__))
|
27
29
|
end
|
30
|
+
|
28
31
|
def self.resource(resource_path)
|
29
32
|
File.join(root, resource_path)
|
30
33
|
end
|
@@ -0,0 +1,355 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
def self.all_loaded_classes
|
3
|
+
@all_loaded_classes ||= []
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.last_loaded_class
|
7
|
+
@last_loaded_class ||= nil
|
8
|
+
end
|
9
|
+
|
10
|
+
class Base
|
11
|
+
def self.singleton_class
|
12
|
+
Class.new do
|
13
|
+
def send(*_p, **_o); end
|
14
|
+
end.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.class_info
|
18
|
+
return @class_info if defined? @class_info
|
19
|
+
|
20
|
+
ActiveRecord.last_loaded_class = name
|
21
|
+
|
22
|
+
@class_info = {
|
23
|
+
class_name: name
|
24
|
+
}
|
25
|
+
|
26
|
+
ActiveRecord.all_loaded_classes << class_info
|
27
|
+
|
28
|
+
@class_info
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.set(key, value)
|
32
|
+
class_info[key] = class_info[key] || {}
|
33
|
+
class_info[key] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.add(key, value)
|
37
|
+
class_info[key] = class_info[key] || []
|
38
|
+
if value.is_a?(Array)
|
39
|
+
class_info[key] = class_info[key] + value
|
40
|
+
else
|
41
|
+
class_info[key] << value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.custom_set(key, value = {})
|
46
|
+
class_info[:custom] = {} unless class_info[:custom]
|
47
|
+
class_info[:custom][key] = class_info[:custom][key] || {}
|
48
|
+
class_info[:custom][key] = value
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.custom_add(key, value)
|
52
|
+
class_info[:custom] = {} unless class_info[:custom]
|
53
|
+
class_info[:custom][key] = class_info[:custom][key] || []
|
54
|
+
if value.is_a?(Array)
|
55
|
+
class_info[:custom][key] = class_info[:custom][key] + value
|
56
|
+
else
|
57
|
+
class_info[:custom][key] << value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# examples:
|
62
|
+
# enum status: { active: 0, archived: 1 }
|
63
|
+
# enum status: [:active, :archived]
|
64
|
+
# enum status: [:active, :archived], _suffix: true
|
65
|
+
# enum comments_status: [:active, :inactive], _prefix: :comments
|
66
|
+
def self.enum(**opts)
|
67
|
+
add(:enum, opts)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.attr_accessor(*names)
|
71
|
+
add(:attr_accessor, names)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.attr_reader(*names)
|
75
|
+
add(:attr_reader, names)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.attr_writer(*names)
|
79
|
+
add(:attr_writer, names)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.lambda_source(a_lambda, prefix = nil)
|
83
|
+
return nil unless a_lambda
|
84
|
+
|
85
|
+
puts 'NOT A LAMBDA' unless a_lambda.is_a?(Proc)
|
86
|
+
|
87
|
+
result = a_lambda&.source&.strip
|
88
|
+
result = result&.delete_prefix(prefix) if prefix
|
89
|
+
result&.strip
|
90
|
+
end
|
91
|
+
|
92
|
+
# examples
|
93
|
+
# default_scope where(:published => true) # NOT supported
|
94
|
+
# default_scope { where(:published_at => Time.now - 1.week) }
|
95
|
+
# default_scope -> { order(:external_updated_at) }
|
96
|
+
# default_scope -> { where(:published => true) }, all_queries: true
|
97
|
+
def self.default_scope(**opts, &block)
|
98
|
+
block_source = nil
|
99
|
+
block_source = lambda_source(block, 'default_scope') if block_given?
|
100
|
+
|
101
|
+
set(:default_scope, opts.merge(block: block_source))
|
102
|
+
end
|
103
|
+
|
104
|
+
# examples
|
105
|
+
# scope :red, where(:color => 'red') # NOT SUPPORTED
|
106
|
+
# scope :dry_clean_only, joins(:washing_instructions).where('washing_instructions.dry_clean_only = ?', true) # NOT SUPPORTED
|
107
|
+
#
|
108
|
+
def self.scope(name, on_the_lamb = nil, **opts)
|
109
|
+
lamb_source = lambda_source(on_the_lamb, "scope :#{name},")
|
110
|
+
|
111
|
+
add(:scopes, {
|
112
|
+
name: name,
|
113
|
+
opts: opts,
|
114
|
+
block: lamb_source
|
115
|
+
})
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.belongs_to(name, on_the_lamb = nil, **opts)
|
119
|
+
lamb_source = lambda_source(on_the_lamb, "belongs_to :#{name},")
|
120
|
+
|
121
|
+
add(:belongs_to, {
|
122
|
+
name: name,
|
123
|
+
opts: opts,
|
124
|
+
block: lamb_source
|
125
|
+
})
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.has_many(name, on_the_lamb = nil, **opts)
|
129
|
+
lamb_source = lambda_source(on_the_lamb, "has_many :#{name},")
|
130
|
+
|
131
|
+
add(:has_many, {
|
132
|
+
name: name,
|
133
|
+
opts: opts,
|
134
|
+
block: lamb_source
|
135
|
+
})
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.has_one(name, on_the_lamb = nil, **opts)
|
139
|
+
lamb_source = lambda_source(on_the_lamb, "has_one :#{name},")
|
140
|
+
|
141
|
+
add(:has_one, {
|
142
|
+
name: name,
|
143
|
+
opts: opts,
|
144
|
+
block: lamb_source
|
145
|
+
})
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.has_and_belongs_to_many(name, on_the_lamb = nil, **opts)
|
149
|
+
lamb_source = lambda_source(on_the_lamb, "has_and_belongs_to_many :#{name},")
|
150
|
+
|
151
|
+
add(:has_and_belongs_to_many, {
|
152
|
+
name: name,
|
153
|
+
opts: opts,
|
154
|
+
block: lamb_source
|
155
|
+
})
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.validate(*names, **opts, &block)
|
159
|
+
block_source = nil
|
160
|
+
block_source = lambda_source(block, 'validate') if block_given?
|
161
|
+
|
162
|
+
set(:default_scope, opts.merge(block: block_source))
|
163
|
+
|
164
|
+
add(:validate, {
|
165
|
+
names: names,
|
166
|
+
opts: opts,
|
167
|
+
block: block_source
|
168
|
+
})
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.validates(name, **opts)
|
172
|
+
add(:validates, {
|
173
|
+
name: name,
|
174
|
+
opts: opts
|
175
|
+
})
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.alias_attribute(left, right)
|
179
|
+
add(:alias_attribute, {
|
180
|
+
left: left,
|
181
|
+
right: right
|
182
|
+
})
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.before_create(name)
|
186
|
+
add(:before_create, {
|
187
|
+
name: name
|
188
|
+
})
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.before_save(name)
|
192
|
+
add(:before_save, {
|
193
|
+
name: name
|
194
|
+
})
|
195
|
+
end
|
196
|
+
|
197
|
+
def self.before_destroy(name)
|
198
|
+
add(:before_destroy, {
|
199
|
+
name: name
|
200
|
+
})
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.before_validation(name = nil, &block)
|
204
|
+
block_source = nil
|
205
|
+
block_source = lambda_source(block, 'before_validation') if block_given?
|
206
|
+
|
207
|
+
add(:before_validation, {
|
208
|
+
name: name,
|
209
|
+
block: block_source
|
210
|
+
})
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.after_create(name)
|
214
|
+
add(:after_create, {
|
215
|
+
name: name
|
216
|
+
})
|
217
|
+
end
|
218
|
+
|
219
|
+
def self.after_save(name)
|
220
|
+
add(:after_save, {
|
221
|
+
name: name
|
222
|
+
})
|
223
|
+
end
|
224
|
+
|
225
|
+
def self.after_destroy(name = nil, &block)
|
226
|
+
block_source = nil
|
227
|
+
block_source = lambda_source(block, 'after_destroy') if block_given?
|
228
|
+
|
229
|
+
add(:after_destroy, {
|
230
|
+
name: name,
|
231
|
+
block: block_source
|
232
|
+
})
|
233
|
+
end
|
234
|
+
|
235
|
+
def self.after_commit(name)
|
236
|
+
add(:after_commit, {
|
237
|
+
name: name
|
238
|
+
})
|
239
|
+
end
|
240
|
+
|
241
|
+
def self.accepts_nested_attributes_for(name, **opts)
|
242
|
+
add(:accepts_nested_attributes_for, {
|
243
|
+
name: name,
|
244
|
+
opts: opts
|
245
|
+
})
|
246
|
+
end
|
247
|
+
|
248
|
+
def self.has_secure_token(name)
|
249
|
+
add(:has_secure_token, {
|
250
|
+
name: name
|
251
|
+
})
|
252
|
+
end
|
253
|
+
|
254
|
+
# CAN THESE BE AUTOMATED LIKE INCLUDE MODULES
|
255
|
+
def self.establish_connection(connection)
|
256
|
+
class_info[:establish_connection] = connection
|
257
|
+
end
|
258
|
+
|
259
|
+
def self.store_accessor(*names)
|
260
|
+
class_info[:store_accessor] = *names
|
261
|
+
end
|
262
|
+
|
263
|
+
def self.table_name=(table_name)
|
264
|
+
class_info[:table_name] = table_name
|
265
|
+
end
|
266
|
+
|
267
|
+
def self.primary_key=(primary_key)
|
268
|
+
class_info[:primary_key] = primary_key
|
269
|
+
end
|
270
|
+
|
271
|
+
def self.require(require)
|
272
|
+
add(:require, require)
|
273
|
+
end
|
274
|
+
|
275
|
+
def self.devise(*names)
|
276
|
+
add(:devise, names)
|
277
|
+
end
|
278
|
+
|
279
|
+
def self.pg_search_scope(name, **opts)
|
280
|
+
custom_set(:pg_search_scope, {
|
281
|
+
name: name,
|
282
|
+
opts: opts
|
283
|
+
})
|
284
|
+
end
|
285
|
+
|
286
|
+
def self.acts_as_readable(**opts)
|
287
|
+
custom_set(:acts_as_readable, {
|
288
|
+
opts: opts
|
289
|
+
})
|
290
|
+
end
|
291
|
+
|
292
|
+
def self.acts_as_reader
|
293
|
+
custom_set(:acts_as_reader, {})
|
294
|
+
end
|
295
|
+
|
296
|
+
def self.acts_as_commentable
|
297
|
+
custom_set(:acts_as_commentable, {})
|
298
|
+
end
|
299
|
+
|
300
|
+
def self.acts_as_list(**opts)
|
301
|
+
custom_set(:acts_as_list, {
|
302
|
+
opts: opts
|
303
|
+
})
|
304
|
+
end
|
305
|
+
|
306
|
+
def self.has_paper_trail
|
307
|
+
custom_set(:has_paper_trail)
|
308
|
+
end
|
309
|
+
|
310
|
+
def self.validates_uniqueness_of(name, **opts)
|
311
|
+
custom_set(:validates_uniqueness_of, {
|
312
|
+
name: name,
|
313
|
+
opts: opts
|
314
|
+
})
|
315
|
+
end
|
316
|
+
|
317
|
+
def self.validates_presence_of(name, **opts)
|
318
|
+
custom_set(:validates_presence_of, {
|
319
|
+
name: name,
|
320
|
+
opts: opts
|
321
|
+
})
|
322
|
+
end
|
323
|
+
|
324
|
+
def self.validates_length_of(name, **opts)
|
325
|
+
custom_set(:validates_length_of, {
|
326
|
+
name: name,
|
327
|
+
opts: opts
|
328
|
+
})
|
329
|
+
end
|
330
|
+
|
331
|
+
def self.attr_encrypted(name, **opts)
|
332
|
+
custom_set(:attr_encrypted, {
|
333
|
+
name: name,
|
334
|
+
opts: opts
|
335
|
+
})
|
336
|
+
end
|
337
|
+
|
338
|
+
def self.validates_confirmation_of(name, **opts)
|
339
|
+
custom_set(:validates_confirmation_of, {
|
340
|
+
name: name,
|
341
|
+
opts: opts
|
342
|
+
})
|
343
|
+
end
|
344
|
+
|
345
|
+
def self.with_options(opts, &block)
|
346
|
+
block_source = nil
|
347
|
+
block_source = lambda_source(block) if block_given?
|
348
|
+
|
349
|
+
custom_add(:with_options, {
|
350
|
+
opts: opts,
|
351
|
+
block: block_source
|
352
|
+
})
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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
|
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.
|
4
|
+
version: 0.0.16
|
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-
|
11
|
+
date: 2021-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -104,7 +104,10 @@ files:
|
|
104
104
|
- lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb
|
105
105
|
- lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb
|
106
106
|
- lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb
|
107
|
-
- lib/k_domain/domain_model/transform_steps/
|
107
|
+
- lib/k_domain/domain_model/transform_steps/step8_rails_resource_models.rb
|
108
|
+
- lib/k_domain/domain_model/transform_steps/step9_rails_structure_models.rb
|
109
|
+
- lib/k_domain/rails_code_extractor/extract_model.rb
|
110
|
+
- lib/k_domain/rails_code_extractor/load_shim.rb
|
108
111
|
- lib/k_domain/raw_db_schema/load.rb
|
109
112
|
- lib/k_domain/raw_db_schema/transform.rb
|
110
113
|
- lib/k_domain/schemas/_.rb
|
@@ -139,6 +142,8 @@ files:
|
|
139
142
|
- lib/k_domain/schemas/investigate.rb
|
140
143
|
- lib/k_domain/schemas/rails_resource.rb
|
141
144
|
- lib/k_domain/version.rb
|
145
|
+
- templates/active_record_shims.rb
|
146
|
+
- templates/fake_module_shims.rb
|
142
147
|
- templates/load_schema.rb
|
143
148
|
homepage: http://appydave.com/gems/k-domain
|
144
149
|
licenses:
|