k_domain 0.0.11 → 0.0.20

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -1
  3. data/Gemfile +1 -1
  4. data/Rakefile +3 -1
  5. data/STORIES.md +35 -6
  6. data/k_domain.gemspec +1 -0
  7. data/lib/k_domain/domain_model/load.rb +8 -2
  8. data/lib/k_domain/domain_model/transform.rb +24 -49
  9. data/lib/k_domain/domain_model/transform_steps/_.rb +3 -3
  10. data/lib/k_domain/domain_model/transform_steps/step.rb +36 -11
  11. data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +1 -1
  12. data/lib/k_domain/domain_model/transform_steps/{step8_locate_rails_models.rb → step4_rails_resource_models.rb} +5 -3
  13. data/lib/k_domain/domain_model/transform_steps/step5_rails_models.rb +71 -0
  14. data/lib/k_domain/domain_model/transform_steps/{step5_attach_dictionary.rb → step6_attach_dictionary.rb} +9 -3
  15. data/lib/k_domain/rails_code_extractor/extract_model.rb +58 -0
  16. data/lib/k_domain/rails_code_extractor/shim_loader.rb +29 -0
  17. data/lib/k_domain/raw_db_schema/load.rb +8 -2
  18. data/lib/k_domain/raw_db_schema/transform.rb +5 -6
  19. data/lib/k_domain/schemas/_.rb +16 -0
  20. data/lib/k_domain/schemas/database/_.rb +0 -7
  21. data/lib/k_domain/schemas/database/index.rb +1 -1
  22. data/lib/k_domain/schemas/database/schema.rb +15 -2
  23. data/lib/k_domain/schemas/database/table.rb +19 -8
  24. data/lib/k_domain/schemas/dictionary.rb +19 -0
  25. data/lib/k_domain/schemas/domain/_.rb +0 -3
  26. data/lib/k_domain/schemas/domain/domain.rb +1 -2
  27. data/lib/k_domain/schemas/domain/erd_file.rb +2 -0
  28. data/lib/k_domain/schemas/domain_model.rb +15 -0
  29. data/lib/k_domain/schemas/{domain/investigate.rb → investigate.rb} +1 -1
  30. data/lib/k_domain/schemas/rails_resource.rb +16 -0
  31. data/lib/k_domain/schemas/rails_structure.rb +92 -0
  32. data/lib/k_domain/version.rb +1 -1
  33. data/lib/k_domain.rb +13 -3
  34. data/templates/active_record_shims.rb +368 -0
  35. data/templates/fake_module_shims.rb +42 -0
  36. data/{lib/k_domain/raw_db_schema/template.rb → templates/load_schema.rb} +4 -4
  37. metadata +16 -12
  38. data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +0 -454
  39. data/lib/k_domain/schemas/database/column.rb +0 -16
  40. data/lib/k_domain/schemas/database/database.rb +0 -11
  41. data/lib/k_domain/schemas/database/unique_key.rb +0 -14
  42. data/lib/k_domain/schemas/domain/dictionary.rb +0 -17
  43. data/lib/k_domain/schemas/domain/schema.rb +0 -13
@@ -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
@@ -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.20
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-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,25 +102,23 @@ files:
102
102
  - lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb
103
103
  - lib/k_domain/domain_model/transform_steps/step2_attach_models.rb
104
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
105
+ - lib/k_domain/domain_model/transform_steps/step4_rails_resource_models.rb
106
+ - lib/k_domain/domain_model/transform_steps/step5_rails_models.rb
107
+ - lib/k_domain/domain_model/transform_steps/step6_attach_dictionary.rb
108
+ - lib/k_domain/rails_code_extractor/extract_model.rb
109
+ - lib/k_domain/rails_code_extractor/shim_loader.rb
108
110
  - lib/k_domain/raw_db_schema/load.rb
109
- - lib/k_domain/raw_db_schema/template.rb
110
111
  - lib/k_domain/raw_db_schema/transform.rb
112
+ - lib/k_domain/schemas/_.rb
111
113
  - lib/k_domain/schemas/database/_.rb
112
- - lib/k_domain/schemas/database/column.rb
113
- - lib/k_domain/schemas/database/database.rb
114
114
  - lib/k_domain/schemas/database/foreign_key.rb
115
115
  - lib/k_domain/schemas/database/index.rb
116
116
  - lib/k_domain/schemas/database/schema.rb
117
117
  - lib/k_domain/schemas/database/table.rb
118
- - lib/k_domain/schemas/database/unique_key.rb
118
+ - lib/k_domain/schemas/dictionary.rb
119
119
  - lib/k_domain/schemas/domain/_.rb
120
- - lib/k_domain/schemas/domain/dictionary.rb
121
120
  - lib/k_domain/schemas/domain/domain.rb
122
121
  - lib/k_domain/schemas/domain/erd_file.rb
123
- - lib/k_domain/schemas/domain/investigate.rb
124
122
  - lib/k_domain/schemas/domain/models/column.rb
125
123
  - lib/k_domain/schemas/domain/models/model.rb
126
124
  - lib/k_domain/schemas/domain/old/belongs_to.rb
@@ -139,8 +137,14 @@ files:
139
137
  - lib/k_domain/schemas/domain/old/statistics.rb
140
138
  - lib/k_domain/schemas/domain/old/validate.rb
141
139
  - lib/k_domain/schemas/domain/old/validates.rb
142
- - lib/k_domain/schemas/domain/schema.rb
140
+ - lib/k_domain/schemas/domain_model.rb
141
+ - lib/k_domain/schemas/investigate.rb
142
+ - lib/k_domain/schemas/rails_resource.rb
143
+ - lib/k_domain/schemas/rails_structure.rb
143
144
  - lib/k_domain/version.rb
145
+ - templates/active_record_shims.rb
146
+ - templates/fake_module_shims.rb
147
+ - templates/load_schema.rb
144
148
  homepage: http://appydave.com/gems/k-domain
145
149
  licenses:
146
150
  - MIT
@@ -1,454 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Attach source code found in rails model definitions to models
4
- class Step4AttachErdFiles < KDomain::DomainModel::Step
5
- attr_accessor :ruby_code
6
-
7
- # NOTE: This code could be rewritten using monkey patched modules and peak
8
- def call
9
- domain[:erd_files] = domain_models.map { |model| load_dsl(model) }
10
- end
11
-
12
- private
13
-
14
- def reset_dsl
15
- @ruby_code = nil
16
- @dsl = nil
17
- end
18
-
19
- def dsl
20
- @dsl ||= {
21
- name: '',
22
- name_plural: ''
23
- }
24
- end
25
-
26
- def load_dsl(model)
27
- reset_dsl
28
-
29
- dsl[:name] = model[:name]
30
- dsl[:name_plural] = model[:name_plural]
31
- dsl[:dsl_file] = model[:erd_location][:exist] ? model[:erd_location][:file] : ''
32
-
33
- return dsl unless File.exist?(dsl[:dsl_file])
34
-
35
- @ruby_code = File.read(dsl[:dsl_file])
36
-
37
- dsl[:source] = read_dsl_source
38
- dsl[:dsl] = build_dsl
39
- dsl[:todo] = todo
40
-
41
- dsl
42
- end
43
-
44
- def read_dsl_source
45
- regex_split_private_public = /(?<public>.+?)(?=\bprivate\b)(?<private>.*)/m
46
-
47
- split_code = regex_split_private_public.match(ruby_code)
48
-
49
- public_code = nil
50
- private_code = nil
51
-
52
- if split_code
53
- public_code = split_code[:public]
54
- private_code = split_code[:private]
55
- end
56
-
57
- {
58
- ruby: ruby_code,
59
- public: public_code,
60
- private: private_code,
61
- all_methods: grab_methods(public_code, private_code)
62
- }
63
- end
64
-
65
- def build_dsl
66
- return if ruby_code.nil?
67
-
68
- # need to support options as hash instead of options as string in the future
69
- {
70
- default_scope: grab_default_scope,
71
- scopes: grab_scopes,
72
- belongs_to: grab_belongs_to,
73
- has_one: grab_has_one,
74
- has_many: grab_has_many,
75
- has_and_belongs_to_many: grab_has_and_belongs_to_many,
76
- validate_on: grab_validate,
77
- validates_on: grab_validates
78
- }
79
-
80
- # ^(?<spaces>\s*)(?<event_type>before_create|before_save|before_destroy|after_create|after_save|after_destroy) (:(?<name>\w*)[, ]?(?<scope>.*)|(?<scope>\{.*?\}.*$))
81
- end
82
-
83
- def grab_default_scope
84
- regex = /default_scope \{(?<scope>.*?)\}/m
85
-
86
- m = regex.match(ruby_code)
87
-
88
- return "{ #{m[:scope].strip.gsub('\n', '')} }" if m
89
-
90
- nil
91
- end
92
-
93
- def grab_scopes
94
- entries = []
95
- # Start from beginning of line and capture
96
- # - number of spaces scope
97
- # - name of scope
98
- # - value of scope to end of line
99
- regex = /^(?<spaces>\s*)scope :(?<name>\w*)[, ]?(?<scope>.*)/
100
-
101
- # rubocop:disable Metrics/BlockLength
102
- ruby_code.scan(regex) do
103
- m = $LAST_MATCH_INFO
104
- spaces = m[:spaces] # .delete("\n")
105
- last_lf = spaces.rindex("\n")
106
- spaces = last_lf ? spaces[spaces.rindex("\n") + 1..-1] : spaces
107
- name = m[:name]
108
- scope = m[:scope].strip
109
-
110
- # Found a valid one liner
111
- if scope.ends_with?('}') && (scope.scan(/{/).count == scope.scan(/}/).count)
112
- scope = escape_single_quote(scope)
113
- entries << { name: name, scope: scope }
114
- else
115
- # Have a multiline scope, lets see if it is cleanly formatted
116
-
117
- start_anchor = "#{spaces}scope :#{name}"
118
- end_anchor = "#{spaces}}"
119
-
120
- # log.kv 'spaces', spaces.length
121
- # log.kv 'name', name
122
- # log.kv 'start_anchor', start_anchor
123
- # log.kv 'end_anchor', end_anchor
124
-
125
- start_index = ruby_code.index(/#{start_anchor}/)
126
-
127
- if start_index.nil?
128
- log.error("[#{@current_entity[:name]}] could not find [start] anchor index for [#{name}]")
129
- else
130
- ruby_section = ruby_code[start_index..-1]
131
- end_index = ruby_section.index(/^#{end_anchor}/) # Add ^ start of line
132
- if end_index.nil?
133
- log.error("[#{@current_entity[:name]}] could not find [end] anchor index for [#{name}]")
134
- else
135
- scope = ruby_section[start_anchor.length + 1..end_index].strip
136
- scope = escape_single_quote("#{scope}#{end_anchor}")
137
- entries << { name: name, scope: scope }
138
- end
139
- end
140
- end
141
- end
142
- entries
143
- rescue StandardError => e
144
- # bin ding.pry
145
- puts e.message
146
- end
147
- # rubocop:enable Metrics/BlockLength
148
-
149
- def grab_belongs_to
150
- entries = []
151
-
152
- # Start from beginning of line and capture
153
- # - number of spaces before belongs_to
154
- # - name of the belongs_to
155
- # - value of belongs_to to end of line
156
- regex = /^(?<spaces>\s*)belongs_to :(?<name>\w*)[, ]?(?<options>.*)/
157
-
158
- ruby_code.scan(regex) do
159
- m = $LAST_MATCH_INFO
160
-
161
- # spaces = m[:spaces] # .delete("\n")
162
- # last_lf = spaces.rindex("\n")
163
- # spaces = last_lf ? spaces[spaces.rindex("\n") + 1..-1] : spaces
164
- name = m[:name]
165
-
166
- options = m[:options]
167
- .gsub(':polymorphic => ', 'polymorphic: ')
168
- .gsub(':class_name => ', 'class_name: ')
169
- .gsub(':foreign_key => ', 'foreign_key: ')
170
- .strip
171
-
172
- options = clean_lambda(options)
173
-
174
- entries << { name: name, options: extract_options(options), raw_options: options }
175
- end
176
- entries
177
- rescue StandardError => e
178
- # bin ding.pry
179
- puts e.message
180
- end
181
-
182
- def grab_has_one
183
- entries = []
184
-
185
- # Start from beginning of line and capture
186
- # - number of spaces before has_one
187
- # - name of the has_one
188
- # - value of has_one to end of line
189
- regex = /^(?<spaces>\s*)has_one :(?<name>\w*)[, ]?(?<options>.*)/
190
-
191
- ruby_code.scan(regex) do
192
- m = $LAST_MATCH_INFO
193
-
194
- # spaces = m[:spaces] # .delete("\n")
195
- # last_lf = spaces.rindex("\n")
196
- # spaces = last_lf ? spaces[spaces.rindex("\n") + 1..-1] : spaces
197
- name = m[:name]
198
- options = m[:options]
199
- .strip
200
- # .gsub(':polymorphic => ', 'polymorphic: ')
201
- # .gsub(':class_name => ', 'class_name: ')
202
- # .gsub(':foreign_key => ', 'foreign_key: ')
203
-
204
- options = clean_lambda(options)
205
-
206
- entries << { name: name, options: extract_options(options), raw_options: options }
207
- end
208
- entries
209
- rescue StandardError => e
210
- # bin ding.pry
211
- puts e.message
212
- end
213
-
214
- def grab_has_many
215
- entries = []
216
- # Start from beginning of line and capture
217
- # - number of spaces before has_many
218
- # - name of the has_many
219
- # - value of has_many to end of line
220
- regex = /^(?<spaces>\s*)has_many :(?<name>\w*)[, ]?(?<options>.*)/
221
-
222
- ruby_code.scan(regex) do
223
- m = $LAST_MATCH_INFO
224
-
225
- # spaces = m[:spaces] # .delete("\n")
226
- # last_lf = spaces.rindex("\n")
227
- # spaces = last_lf ? spaces[spaces.rindex("\n") + 1..-1] : spaces
228
- name = m[:name]
229
- options = m[:options]
230
- .gsub(':dependent => ', 'dependent: ')
231
- .gsub(':class_name => ', 'class_name: ')
232
- .gsub(':foreign_key => ', 'foreign_key: ')
233
- .gsub(':primary_key => ', 'primary_key: ')
234
- .strip
235
-
236
- options = clean_lambda(options)
237
-
238
- entries << { name: name, options: extract_options(options), raw_options: options }
239
- end
240
- entries
241
- rescue StandardError => e
242
- # bin ding.pry
243
- puts e.message
244
- end
245
-
246
- def grab_has_and_belongs_to_many
247
- entries = []
248
- # Start from beginning of line and capture
249
- # - number of spaces before has_and_belongs_to_many
250
- # - name of the has_and_belongs_to_many
251
- # - value of has_and_belongs_to_many to end of line
252
- regex = /^(?<spaces>\s*)has_and_belongs_to_many :(?<name>\w*)[, ]?(?<options>.*)/
253
-
254
- ruby_code.scan(regex) do
255
- m = $LAST_MATCH_INFO
256
-
257
- # spaces = m[:spaces] # .delete("\n")
258
- # last_lf = spaces.rindex("\n")
259
- # spaces = last_lf ? spaces[spaces.rindex("\n") + 1..-1] : spaces
260
- name = m[:name]
261
- options = m[:options]
262
- .gsub(':dependent => ', 'dependent: ')
263
- .gsub(':class_name => ', 'class_name: ')
264
- .gsub(':foreign_key => ', 'foreign_key: ')
265
- .gsub(':primary_key => ', 'primary_key: ')
266
- .strip
267
-
268
- options = clean_lambda(options)
269
-
270
- entries << { name: name, options: {}, raw_options: options }
271
- end
272
- entries
273
- rescue StandardError => e
274
- # bin ding.pry
275
- puts e.message
276
- end
277
-
278
- def grab_validates
279
- entries = []
280
- # Start from beginning of line and capture
281
- # - number of spaces before validates
282
- # - name of the validates
283
- # - value of validates to end of line
284
- regex = /^(?<spaces>\s*)validates :(?<name>\w*)[, ]?(?<options>.*)/
285
-
286
- ruby_code.scan(regex) do
287
- m = $LAST_MATCH_INFO
288
-
289
- # spaces = m[:spaces] # .delete("\n")
290
- # last_lf = spaces.rindex("\n")
291
- # spaces = last_lf ? spaces[spaces.rindex("\n") + 1..-1] : spaces
292
- name = m[:name]
293
-
294
- options = m[:options].strip
295
-
296
- options = clean_lambda(options)
297
-
298
- entries << { name: name, raw_options: options }
299
- end
300
- entries
301
- rescue StandardError => e
302
- # bin ding.pry
303
- puts e.message
304
- end
305
-
306
- def grab_validate
307
- entries = []
308
- # Start from beginning of line and capture
309
- # - number of spaces before validate
310
- # - list of methods to call until to end of line
311
- # regex = /^(?<spaces>\s*)validate :(?<name>\w*)[, ]?(?<options>.*)/
312
- regex = /^(?<spaces>\s*)validate (?<line>:.*)/
313
- # puts @current_entity[:name]
314
-
315
- ruby_code.scan(regex) do
316
- m = $LAST_MATCH_INFO
317
-
318
- # spaces = m[:spaces] # .delete("\n")
319
- # last_lf = spaces.rindex("\n")
320
- # spaces = last_lf ? spaces[spaces.rindex("\n") + 1..-1] : spaces
321
- line = m[:line]
322
-
323
- entries << { line: line }
324
- # puts @current_entity[:validate]
325
- end
326
- entries
327
- rescue StandardError => e
328
- # bin ding.pry
329
- puts e.message
330
- end
331
-
332
- def grab_methods(public_code = ruby_code, private_code = nil)
333
- # public_code = ruby_code_public.nil? ? ruby_code : ruby_code_public
334
- # private_code = ruby_code_private
335
-
336
- regex = /def (?<method>.*)/
337
-
338
- # log.info(@current_entity[:name])
339
-
340
- public_methods = parse_methods(:public, public_code&.scan(regex)&.flatten || [])
341
- private_methods = parse_methods(:private, private_code&.scan(regex)&.flatten || [])
342
- methods = (public_methods + private_methods)
343
-
344
- class_methods = methods.select { |method| method[:class_method] == true }
345
-
346
- all_instance = methods.select { |method| method[:class_method] == false }
347
- instance_public = all_instance.select { |method| method[:scope] == :public }
348
- instance_private = all_instance.select { |method| method[:scope] == :private }
349
-
350
- {
351
- klass: class_methods,
352
- instance: all_instance,
353
- instance_public: instance_public,
354
- instance_private: instance_private
355
- }
356
- end
357
-
358
- def parse_methods(scope, methods)
359
- methods.map do |value|
360
- class_method = value.starts_with?('self.')
361
- name = class_method ? value[5..-1] : value
362
- arguments = nil
363
- arguments_index = name.index('(')
364
-
365
- if arguments_index
366
- arguments = name[arguments_index..-1]
367
- name = name[0..arguments_index - 1]
368
- end
369
-
370
- arguments = escape_single_quote(arguments)
371
-
372
- {
373
- name: name,
374
- scope: scope,
375
- class_method: class_method,
376
- arguments: arguments&.strip.to_s
377
- }
378
- end
379
- end
380
-
381
- def todo
382
- {
383
- after_destroy: [], # to do
384
- before_save: [], # to do
385
- after_save: [], # to do
386
- before_create: [], # to do
387
- after_create: [], # to do
388
- enum: [], # to do
389
- attr_encrypted: [], # to do
390
- validates_uniqueness_of: [], # to do
391
- validates_confirmation_of: [], # to do
392
- attr_accessor: [], # to do
393
- attr_reader: [], # to do
394
- attr_writer: [] # to do
395
- }
396
- end
397
-
398
- def escape_single_quote(value)
399
- return nil if value.nil?
400
-
401
- value.gsub("'", "\\\\'")
402
- end
403
-
404
- # rubocop:disable Style/EvalWithLocation, Security/Eval, Style/DocumentDynamicEvalDefinition
405
- def extract_options(options)
406
- eval("{ #{options} }")
407
- rescue StandardError => e
408
- investigate(
409
- step: :step4_attach_erd_files_models,
410
- location: :extract_options,
411
- key: nil,
412
- message: e.message
413
- )
414
- {}
415
- rescue SyntaxError => e
416
- # may be the issue is from a comment at the off the line
417
- comment_index = options.rindex('#') - 1
418
-
419
- if comment_index.positive?
420
- options_minus_comment = options[0..comment_index].squish
421
- return extract_options(options_minus_comment)
422
- end
423
-
424
- investigate(
425
- step: :step4_attach_erd_files_models,
426
- location: :extract_options,
427
- key: nil,
428
- message: e.message
429
- )
430
- {}
431
- end
432
- # rubocop:enable Style/EvalWithLocation, Security/Eval, Style/DocumentDynamicEvalDefinition
433
-
434
- def clean_lambda(options)
435
- if /^->/.match?(options)
436
- index = options.index(/}\s*,/)
437
- if index.nil?
438
- if options.count('{') == options.count('}')
439
- index = options.rindex(/}/)
440
- options = "a_lambda: '#{escape_single_quote(options[0..index])}'"
441
- else
442
- log.error(options)
443
- options = "a_lambda: '#{escape_single_quote(options)}'"
444
- end
445
- else
446
- options = "a_lambda: '#{escape_single_quote(options[0..index])}', #{options[index + 2..-1]}"
447
- end
448
- end
449
- options
450
- rescue StandardError => e
451
- # bin ding.pry
452
- puts e.message
453
- end
454
- end
@@ -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
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # DomainModel holds the entire domain model including database and ancillary information
4
- module KDomain
5
- module DomainModel
6
- class Schema < Dry::Struct
7
- attribute :domain , KDomain::DomainModel::Domain
8
- attribute :database , KDomain::Database::Schema
9
- # attribute :rails_files , KDomain::RailsFiles::Schema
10
- attribute :investigate , KDomain::DomainModel::Investigate
11
- end
12
- end
13
- end