k_domain 0.0.20 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/config/_.rb +3 -0
- data/.builders/setup.rb +30 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -2
- data/Guardfile +1 -0
- data/README.md +15 -0
- data/lib/k_domain/domain_model/transform.rb +23 -13
- 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 +90 -0
- data/lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb +109 -0
- data/lib/k_domain/domain_model/transform_steps/{step3_attach_columns.rb → step8_domain_columns.rb} +40 -73
- data/lib/k_domain/rails_code_extractor/_.rb +5 -0
- data/lib/k_domain/rails_code_extractor/extract_controller.rb +59 -0
- data/lib/k_domain/rails_code_extractor/extract_model.rb +19 -8
- data/lib/k_domain/rails_code_extractor/shim_loader.rb +1 -0
- data/lib/k_domain/raw_db_schema/load.rb +1 -1
- data/lib/k_domain/raw_db_schema/transform.rb +2 -1
- data/lib/k_domain/schemas/_.rb +2 -2
- data/lib/k_domain/schemas/database.rb +86 -0
- data/lib/k_domain/schemas/domain.rb +154 -0
- data/lib/k_domain/schemas/domain_model.rb +2 -2
- data/lib/k_domain/schemas/rails_resource.rb +43 -6
- data/lib/k_domain/schemas/rails_structure.rb +94 -14
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +1 -2
- data/templates/custom/action_controller.rb +36 -0
- data/templates/custom/controller_interceptors.rb +78 -0
- data/templates/custom/model_interceptors.rb +71 -0
- data/templates/load_schema.rb +7 -0
- data/templates/old_printspeek_schema copy.rb +231 -0
- data/templates/old_printspeek_schema.rb +233 -0
- data/templates/rails/action_controller.rb +301 -0
- data/templates/{active_record_shims.rb → rails/active_record.rb} +21 -41
- data/templates/ruby_code_extractor/attach_class_info.rb +13 -0
- data/templates/ruby_code_extractor/behaviour_accessors.rb +39 -0
- data/templates/simple/controller_interceptors.rb +2 -0
- metadata +26 -18
- data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +0 -62
- 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
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.23
|
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-
|
11
|
+
date: 2021-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -74,6 +74,8 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- ".builders/config/_.rb"
|
78
|
+
- ".builders/setup.rb"
|
77
79
|
- ".github/workflows/main.yml"
|
78
80
|
- ".gitignore"
|
79
81
|
- ".rspec"
|
@@ -99,28 +101,26 @@ files:
|
|
99
101
|
- lib/k_domain/domain_model/transform.rb
|
100
102
|
- lib/k_domain/domain_model/transform_steps/_.rb
|
101
103
|
- lib/k_domain/domain_model/transform_steps/step.rb
|
102
|
-
- lib/k_domain/domain_model/transform_steps/
|
103
|
-
- lib/k_domain/domain_model/transform_steps/
|
104
|
-
- lib/k_domain/domain_model/transform_steps/
|
104
|
+
- lib/k_domain/domain_model/transform_steps/step1_db_schema.rb
|
105
|
+
- lib/k_domain/domain_model/transform_steps/step20_dictionary.rb
|
106
|
+
- lib/k_domain/domain_model/transform_steps/step2_domain_models.rb
|
105
107
|
- lib/k_domain/domain_model/transform_steps/step4_rails_resource_models.rb
|
106
|
-
- lib/k_domain/domain_model/transform_steps/
|
107
|
-
- lib/k_domain/domain_model/transform_steps/
|
108
|
+
- lib/k_domain/domain_model/transform_steps/step5_rails_resource_routes.rb
|
109
|
+
- lib/k_domain/domain_model/transform_steps/step6_rails_structure_models.rb
|
110
|
+
- lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb
|
111
|
+
- lib/k_domain/domain_model/transform_steps/step8_domain_columns.rb
|
112
|
+
- lib/k_domain/rails_code_extractor/_.rb
|
113
|
+
- lib/k_domain/rails_code_extractor/extract_controller.rb
|
108
114
|
- lib/k_domain/rails_code_extractor/extract_model.rb
|
109
115
|
- lib/k_domain/rails_code_extractor/shim_loader.rb
|
110
116
|
- lib/k_domain/raw_db_schema/load.rb
|
111
117
|
- lib/k_domain/raw_db_schema/transform.rb
|
112
118
|
- lib/k_domain/schemas/_.rb
|
113
|
-
- lib/k_domain/schemas/database
|
114
|
-
- lib/k_domain/schemas/database/foreign_key.rb
|
115
|
-
- lib/k_domain/schemas/database/index.rb
|
116
|
-
- lib/k_domain/schemas/database/schema.rb
|
117
|
-
- lib/k_domain/schemas/database/table.rb
|
119
|
+
- lib/k_domain/schemas/database.rb
|
118
120
|
- lib/k_domain/schemas/dictionary.rb
|
121
|
+
- lib/k_domain/schemas/domain.rb
|
119
122
|
- lib/k_domain/schemas/domain/_.rb
|
120
|
-
- lib/k_domain/schemas/domain/domain.rb
|
121
123
|
- lib/k_domain/schemas/domain/erd_file.rb
|
122
|
-
- lib/k_domain/schemas/domain/models/column.rb
|
123
|
-
- lib/k_domain/schemas/domain/models/model.rb
|
124
124
|
- lib/k_domain/schemas/domain/old/belongs_to.rb
|
125
125
|
- lib/k_domain/schemas/domain/old/column_old.rb
|
126
126
|
- lib/k_domain/schemas/domain/old/domain_statistics.rb
|
@@ -142,9 +142,17 @@ files:
|
|
142
142
|
- lib/k_domain/schemas/rails_resource.rb
|
143
143
|
- lib/k_domain/schemas/rails_structure.rb
|
144
144
|
- lib/k_domain/version.rb
|
145
|
-
- templates/
|
146
|
-
- templates/
|
145
|
+
- templates/custom/action_controller.rb
|
146
|
+
- templates/custom/controller_interceptors.rb
|
147
|
+
- templates/custom/model_interceptors.rb
|
147
148
|
- templates/load_schema.rb
|
149
|
+
- templates/old_printspeek_schema copy.rb
|
150
|
+
- templates/old_printspeek_schema.rb
|
151
|
+
- templates/rails/action_controller.rb
|
152
|
+
- templates/rails/active_record.rb
|
153
|
+
- templates/ruby_code_extractor/attach_class_info.rb
|
154
|
+
- templates/ruby_code_extractor/behaviour_accessors.rb
|
155
|
+
- templates/simple/controller_interceptors.rb
|
148
156
|
homepage: http://appydave.com/gems/k-domain
|
149
157
|
licenses:
|
150
158
|
- MIT
|
@@ -167,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
175
|
- !ruby/object:Gem::Version
|
168
176
|
version: '0'
|
169
177
|
requirements: []
|
170
|
-
rubygems_version: 3.2.
|
178
|
+
rubygems_version: 3.2.33
|
171
179
|
signing_key:
|
172
180
|
specification_version: 4
|
173
181
|
summary: K Domain builds complex domain schemas by combining the database schema with
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Loop through the db_schema tables and build up a
|
4
|
-
# basic model for each table
|
5
|
-
class Step2AttachModels < KDomain::DomainModel::Step
|
6
|
-
# Map database schema to domain model
|
7
|
-
def call
|
8
|
-
raise 'ERD path not supplied' if opts[:erd_path].nil?
|
9
|
-
|
10
|
-
# Schema is re-shaped into a format designed for domain modeling
|
11
|
-
domain[:models] = database_tables.map { |table| model(table) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def model(table)
|
15
|
-
table_name = table[:name].to_s
|
16
|
-
model_name = table_name.singularize
|
17
|
-
|
18
|
-
{
|
19
|
-
name: model_name,
|
20
|
-
name_plural: table_name, # need to check if this is correct as I know it is wrong for account_history_datum
|
21
|
-
table_name: table_name,
|
22
|
-
pk: primary_key(table),
|
23
|
-
erd_location: location(table_name, model_name),
|
24
|
-
statistics: {}, # Load in future step
|
25
|
-
columns: [] # Load in future step
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def primary_key(table)
|
30
|
-
{
|
31
|
-
name: table[:primary_key],
|
32
|
-
type: table[:primary_key_type],
|
33
|
-
exist: !table[:primary_key].nil?
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
# Location of source code
|
38
|
-
def location(table_name, model_name)
|
39
|
-
file_normal = File.join(opts[:erd_path], "#{model_name}.rb")
|
40
|
-
file_custom = File.join(opts[:erd_path], "#{table_name}.rb")
|
41
|
-
file_exist = true
|
42
|
-
state = []
|
43
|
-
|
44
|
-
if File.exist?(file_normal)
|
45
|
-
file = file_normal
|
46
|
-
state.push(:has_ruby_model)
|
47
|
-
elsif File.exist?(file_custom)
|
48
|
-
file = file_custom
|
49
|
-
state.push(:has_ruby_model)
|
50
|
-
state.push(:nonconventional_name)
|
51
|
-
else
|
52
|
-
file = ''
|
53
|
-
file_exist = false
|
54
|
-
end
|
55
|
-
|
56
|
-
{
|
57
|
-
file: file,
|
58
|
-
exist: file_exist,
|
59
|
-
state: state # display_state: state.join(' ')
|
60
|
-
}
|
61
|
-
end
|
62
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Locate rails model files
|
4
|
-
class Step5RailsModels < KDomain::DomainModel::Step
|
5
|
-
def call
|
6
|
-
raise 'ERD path not supplied' unless opts[:erd_path]
|
7
|
-
|
8
|
-
self.rails_structure_models = rails_resource_models.map do |resource|
|
9
|
-
process_resource(OpenStruct.new(resource))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def process_resource(resource)
|
16
|
-
@model = {
|
17
|
-
model_name: resource.model_name,
|
18
|
-
table_name: resource.table_name,
|
19
|
-
file: resource.file,
|
20
|
-
exist: resource.exist,
|
21
|
-
state: resource.state,
|
22
|
-
code: resource.exist ? File.read(resource.file) : '',
|
23
|
-
behaviours: {},
|
24
|
-
functions: {}
|
25
|
-
}
|
26
|
-
|
27
|
-
return @model unless resource.exist
|
28
|
-
|
29
|
-
@model[:behaviours] = extract_model_behavior(resource.file)
|
30
|
-
@model[:functions] = extract_model_functions(resource.file)
|
31
|
-
|
32
|
-
@model
|
33
|
-
end
|
34
|
-
|
35
|
-
def extract_model_behavior(file)
|
36
|
-
extractor.extract(file)
|
37
|
-
extractor.model
|
38
|
-
end
|
39
|
-
|
40
|
-
def extract_model_functions(file)
|
41
|
-
klass_name = File.basename(file, File.extname(file))
|
42
|
-
|
43
|
-
klass = case klass_name
|
44
|
-
when 'clearbit_quota'
|
45
|
-
ClearbitQuota
|
46
|
-
when 'account_history_data'
|
47
|
-
AccountHistoryData
|
48
|
-
else
|
49
|
-
Module.const_get(klass_name.classify)
|
50
|
-
end
|
51
|
-
|
52
|
-
class_info = Peeky.api.build_class_info(klass.new)
|
53
|
-
|
54
|
-
class_info.to_h
|
55
|
-
rescue StandardError => e
|
56
|
-
log.exception(e)
|
57
|
-
end
|
58
|
-
|
59
|
-
def extractor
|
60
|
-
@extractor ||= KDomain::RailsCodeExtractor::ExtractModel.new(shim_loader)
|
61
|
-
end
|
62
|
-
|
63
|
-
def shim_loader
|
64
|
-
return opts[:shim_loader] if !opts[:shim_loader].nil? && opts[:shim_loader].is_a?(KDomain::RailsCodeExtractor::ShimLoader)
|
65
|
-
|
66
|
-
shim_loader = KDomain::RailsCodeExtractor::ShimLoader.new
|
67
|
-
shim_loader.register(:fake_module , KDomain::Gem.resource('templates/fake_module_shims.rb'))
|
68
|
-
shim_loader.register(:active_record, KDomain::Gem.resource('templates/active_record_shims.rb'))
|
69
|
-
shim_loader
|
70
|
-
end
|
71
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module KDomain
|
4
|
-
module Database
|
5
|
-
class ForeignKey < Dry::Struct
|
6
|
-
attribute :left , Types::Strict::String
|
7
|
-
attribute :right , Types::Strict::String
|
8
|
-
attribute :name? , Types::Strict::String.optional.default(nil)
|
9
|
-
attribute :on_update? , Types::Strict::String.optional.default(nil)
|
10
|
-
attribute :on_delete? , Types::Strict::String.optional.default(nil)
|
11
|
-
attribute :column? , Types::Strict::String.optional.default(nil)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module KDomain
|
4
|
-
module Database
|
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
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module KDomain
|
4
|
-
module Database
|
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
|
-
|
19
|
-
class Meta < Dry::Struct
|
20
|
-
attribute :rails , Types::Strict::Integer
|
21
|
-
attribute :db_info , KDomain::Database::Schema::DbInfo
|
22
|
-
attribute :unique_keys , Types::Strict::Array.of(KDomain::Database::Schema::UniqueKey)
|
23
|
-
end
|
24
|
-
|
25
|
-
attribute :tables , Types::Strict::Array.of(KDomain::Database::Table)
|
26
|
-
attribute :foreign_keys? , Types::Strict::Array.of(KDomain::Database::ForeignKey)
|
27
|
-
attribute :indexes? , Types::Strict::Array.of(KDomain::Database::Index)
|
28
|
-
attribute :meta , KDomain::Database::Schema::Meta
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module KDomain
|
4
|
-
module Database
|
5
|
-
class Table < Dry::Struct
|
6
|
-
class RailsSchema < 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
|
-
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
|
-
|
23
|
-
attribute :name , Types::Strict::String
|
24
|
-
attribute :primary_key , Types::Strict::String.optional.default(nil)
|
25
|
-
attribute :primary_key_type , Types::Strict::String.optional.default(nil)
|
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
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Domain class holds a list of the entities
|
4
|
-
module KDomain
|
5
|
-
module DomainModel
|
6
|
-
class Domain < Dry::Struct
|
7
|
-
attribute :models , Types::Strict::Array.of(KDomain::DomainModel::Model)
|
8
|
-
# attribute :erd_files , Types::Strict::Array.of(KDomain::DomainModel::ErdFile)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module KDomain
|
4
|
-
module DomainModel
|
5
|
-
class Column < Dry::Struct
|
6
|
-
attribute :name , Types::Strict::String # "source_account_id"
|
7
|
-
attribute :name_plural , Types::Strict::String # "source_account_ids"
|
8
|
-
attribute :type , Types::Coercible::Symbol # "integer"
|
9
|
-
attribute :precision , Types::Strict::Integer.optional.default(nil) # null
|
10
|
-
attribute :scale , Types::Strict::Integer.optional.default(nil) # null
|
11
|
-
attribute :default , Types::Nominal::Any.optional.default(nil) # null
|
12
|
-
attribute :null , Types::Nominal::Any.optional.default(nil) # null
|
13
|
-
attribute :limit , Types::Strict::Integer.optional.default(nil) # null
|
14
|
-
attribute :array , Types::Strict::Bool.optional.default(nil) # null
|
15
|
-
|
16
|
-
# Calculated value
|
17
|
-
attribute :structure_type , Types::Coercible::Symbol #
|
18
|
-
attribute :foreign_key , Types::Strict::Bool.optional.default(nil) #
|
19
|
-
attribute :foreign_table , Types::Strict::String #
|
20
|
-
attribute :foreign_table_plural , Types::Strict::String #
|
21
|
-
|
22
|
-
# def data_column
|
23
|
-
# @columns_data ||= structure_type?(:data)
|
24
|
-
# end
|
25
|
-
|
26
|
-
# def structure_type?(*structure_types)
|
27
|
-
# structure_types.include?(column.structure_type)
|
28
|
-
# end
|
29
|
-
|
30
|
-
def db_type
|
31
|
-
return @db_type if defined? @db_type
|
32
|
-
|
33
|
-
@db_type = DB_TYPE[type] || '******'
|
34
|
-
end
|
35
|
-
|
36
|
-
def ruby_type
|
37
|
-
return @ruby_type if defined? @ruby_type
|
38
|
-
|
39
|
-
@ruby_type = RUBY_TYPE[type] || '******'
|
40
|
-
end
|
41
|
-
|
42
|
-
def csharp_type
|
43
|
-
return @csharp_type if defined? @csharp_type
|
44
|
-
|
45
|
-
@csharp_type = CSHARP_TYPE[type] || '******'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Domain class holds a list of the entities
|
4
|
-
module KDomain
|
5
|
-
module DomainModel
|
6
|
-
class Model < Dry::Struct
|
7
|
-
class Pk < Dry::Struct
|
8
|
-
attribute :name , Types::Strict::String.optional.default(nil)
|
9
|
-
attribute :type , Types::Strict::String.optional.default(nil)
|
10
|
-
attribute :exist , Types::Strict::Bool
|
11
|
-
end
|
12
|
-
|
13
|
-
class ErdLocation < Dry::Struct
|
14
|
-
attribute :file , Types::Strict::String
|
15
|
-
attribute :exist , Types::Strict::Bool
|
16
|
-
attribute :state , Types::Strict::Array
|
17
|
-
end
|
18
|
-
|
19
|
-
attribute :name , Types::Strict::String
|
20
|
-
attribute :name_plural , Types::Strict::String
|
21
|
-
attribute :table_name , Types::Strict::String
|
22
|
-
# Model type - :entity, :basic_user, :admin_user, possibly: m2m, agg_root
|
23
|
-
attribute :type , Types::Strict::Symbol.optional.default(:entity)
|
24
|
-
attribute :pk , KDomain::DomainModel::Model::Pk
|
25
|
-
attribute :erd_location , KDomain::DomainModel::Model::ErdLocation
|
26
|
-
attribute :columns , Types::Strict::Array.of(KDomain::DomainModel::Column)
|
27
|
-
|
28
|
-
def ruby?
|
29
|
-
location.exist
|
30
|
-
end
|
31
|
-
|
32
|
-
def pk?
|
33
|
-
pk.exist
|
34
|
-
end
|
35
|
-
|
36
|
-
# If filled in, the model has a main field that is useful for rendering and may be used for unique constraint, may also be called display_name
|
37
|
-
def main_key
|
38
|
-
@main_key ||= MainKey.lookup(name, columns_data)
|
39
|
-
end
|
40
|
-
|
41
|
-
def traits
|
42
|
-
@traits ||= Traits.lookup(name)
|
43
|
-
end
|
44
|
-
|
45
|
-
# def where()
|
46
|
-
# end
|
47
|
-
|
48
|
-
# def columns_where()
|
49
|
-
# end
|
50
|
-
|
51
|
-
# Column filters
|
52
|
-
|
53
|
-
def columns_data
|
54
|
-
@columns_data ||= columns_for_structure_types(:data)
|
55
|
-
end
|
56
|
-
|
57
|
-
# def columns_data_optional
|
58
|
-
# @columns_data_optional ||= columns_for_structure_types(:data).select { |c| true }
|
59
|
-
# end
|
60
|
-
|
61
|
-
# def columns_data_required
|
62
|
-
# @columns_data_required ||= columns_for_structure_types(:data).select { |c| false }
|
63
|
-
# end
|
64
|
-
|
65
|
-
def columns_primary
|
66
|
-
@columns_primary ||= columns_for_structure_types(:primary_key)
|
67
|
-
end
|
68
|
-
|
69
|
-
def columns_foreign
|
70
|
-
@columns_foreign ||= columns_for_structure_types(:foreign_key)
|
71
|
-
end
|
72
|
-
|
73
|
-
def columns_timestamp
|
74
|
-
@columns_data_timestamp ||= columns_for_structure_types(:timestamp)
|
75
|
-
end
|
76
|
-
|
77
|
-
def columns_deleted_at
|
78
|
-
@columns_data_deleted_at ||= columns_for_structure_types(:deleted_at)
|
79
|
-
end
|
80
|
-
|
81
|
-
def columns_virtual
|
82
|
-
@columns_virtual ||= columns_for_structure_types(:timestamp, :deleted_at)
|
83
|
-
end
|
84
|
-
|
85
|
-
def columns_data_foreign
|
86
|
-
@columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key)
|
87
|
-
end
|
88
|
-
alias rows_fields_and_fk columns_data_foreign
|
89
|
-
|
90
|
-
def columns_data_primary
|
91
|
-
@columns_data_primary ||= columns_for_structure_types(:data, :primary_key)
|
92
|
-
end
|
93
|
-
alias rows_fields_and_pk columns_data_primary
|
94
|
-
|
95
|
-
def columns_data_virtual
|
96
|
-
@columns_data_virtual ||= columns_for_structure_types(:data, :timestamp, :deleted_at)
|
97
|
-
end
|
98
|
-
alias rows_fields_and_virtual columns_data_virtual
|
99
|
-
|
100
|
-
def columns_data_foreign_virtual
|
101
|
-
@columns_data_foreign_virtual ||= columns_for_structure_types(:data, :foreign_key, :timestamp, :deleted_at)
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def columns_for_structure_types(*structure_types)
|
107
|
-
columns.select { |column| structure_types.include?(column.structure_type) }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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
|