k_domain 0.0.16 → 0.0.26
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/.builders/boot.rb +40 -0
- data/.builders/generators/configuration_generator.rb +22 -0
- data/.builders/run.rb +16 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -2
- data/Guardfile +1 -0
- data/README.md +15 -0
- data/STORIES.md +35 -6
- 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/load.rb +41 -0
- data/lib/k_domain/domain_model/transform.rb +27 -55
- data/lib/k_domain/domain_model/transform_steps/_.rb +8 -7
- data/lib/k_domain/domain_model/transform_steps/step.rb +27 -1
- 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/{step5_attach_dictionary.rb → step20_dictionary.rb} +7 -4
- data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +123 -0
- data/lib/k_domain/domain_model/transform_steps/{step8_rails_resource_models.rb → step4_rails_resource_models.rb} +4 -4
- 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 +111 -0
- data/lib/k_domain/domain_model/transform_steps/step8_domain_columns.rb +99 -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 +56 -6
- data/lib/k_domain/rails_code_extractor/{load_shim.rb → shim_loader.rb} +3 -5
- 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 +6 -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 +149 -0
- data/lib/k_domain/schemas/domain_model.rb +6 -5
- data/lib/k_domain/schemas/{domain/_.rb → domain_types.rb} +1 -8
- data/lib/k_domain/schemas/rails_resource.rb +43 -6
- data/lib/k_domain/schemas/rails_structure.rb +182 -0
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +4 -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/rails/action_controller.rb +301 -0
- data/templates/{active_record_shims.rb → rails/active_record.rb} +42 -49
- 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 +33 -22
- 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/step4_attach_erd_files.rb +0 -457
- data/lib/k_domain/domain_model/transform_steps/step9_rails_structure_models.rb +0 -33
- 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
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 86f877b2fd5644c7ebd211c662cb4cd1ff63213dcc3cc588d3485f698a2bc7b9
         | 
| 4 | 
            +
              data.tar.gz: 9999ee5fa153fa7c1833cd21a0a5a145cbee4a97cd11284c1bb4440157ae6d0a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 013e1f7524e395b9766831786cd1f4052eb6000fd35105c58bfb51869f9d1b93151f3fbc3e8fe349f59dd6819daf7d27e22a05ae5f95fba6826bf61af06eb235
         | 
| 7 | 
            +
              data.tar.gz: c56d291ba618e70863e334bca9c1e817da700d6d0769e92ac5fb7d267b1f02068f6d4275e423264147066389d45dca831d3b3878eef45662d0f4ef8457d99e20
         | 
    
        data/.builders/boot.rb
    ADDED
    
    | @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            # Boot Sequence
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            include KLog::Logging
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            CONFIG_KEY = :k_domain
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            log.kv 'working folder', Dir.pwd
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Handlebars::Helpers.configure do |config|
         | 
| 10 | 
            +
              config_file = File.join(Gem.loaded_specs['handlebars-helpers'].full_gem_path, '.handlebars_helpers.json')
         | 
| 11 | 
            +
              config.helper_config_file = config_file
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              string_config_file = File.join(Gem.loaded_specs['handlebars-helpers'].full_gem_path, '.handlebars_string_formatters.json')
         | 
| 14 | 
            +
              config.string_formatter_config_file = string_config_file
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            def builder
         | 
| 18 | 
            +
              @builder ||= KBuilder::BaseBuilder.init(KConfig.configuration(CONFIG_KEY))
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            KConfig.configure(CONFIG_KEY) do |config|
         | 
| 22 | 
            +
              global_template = File.expand_path('~/dev/kgems/k_templates/templates')
         | 
| 23 | 
            +
              config.target_folders.add(:app, File.expand_path('../', Dir.pwd))
         | 
| 24 | 
            +
              config.target_folders.add(:lib_config, :app, 'lib/k_domain/config')
         | 
| 25 | 
            +
              config.template_folders.add(:global_template, global_template)
         | 
| 26 | 
            +
              config.template_folders.add(:app_template, File.expand_path('.templates', Dir.pwd))
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            KConfig.configuration(CONFIG_KEY).debug
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            area = KManager.add_area(CONFIG_KEY)
         | 
| 32 | 
            +
            resource_manager = area.resource_manager
         | 
| 33 | 
            +
            resource_manager.add_resource('https://raw.githubusercontent.com/klueless-io/k_playground/main/ruby/components/configuration/.builders/configuration_director.rb', content_type: :ruby)
         | 
| 34 | 
            +
            resource_manager
         | 
| 35 | 
            +
              .fileset
         | 
| 36 | 
            +
              .glob('*.rb', exclude: ['boot.rb'])
         | 
| 37 | 
            +
              .glob('generators/**/*.rb')
         | 
| 38 | 
            +
            resource_manager.add_resources
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            KManager.boot
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            KManager.action do
         | 
| 2 | 
            +
              def on_action
         | 
| 3 | 
            +
                puts '-' * 70
         | 
| 4 | 
            +
                builder.cd(:lib_config)
         | 
| 5 | 
            +
                director = ConfigurationDirector
         | 
| 6 | 
            +
                  .init(builder, on_exist: :compare)
         | 
| 7 | 
            +
                  .style(:single)
         | 
| 8 | 
            +
                  .name('Domain Configuration')
         | 
| 9 | 
            +
                  .main_namespace('KDomain', 'Config')
         | 
| 10 | 
            +
                  .add_config_key(:default_main_key, "nil")
         | 
| 11 | 
            +
                  .add_config_key(:default_traits, "%i[trait1 trait2 trait3]")
         | 
| 12 | 
            +
                  .add_config_key(:fallback_keys, "%i[]")
         | 
| 13 | 
            +
                  .add_config_key(:entities, "[]")
         | 
| 14 | 
            +
                  # .logit
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                # dom = director.dom
         | 
| 17 | 
            +
                # data = director.data
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                director.add_config
         | 
| 20 | 
            +
                # director.add_configuration
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
    
        data/.builders/run.rb
    ADDED
    
    | @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            # Run
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            KManager.action do
         | 
| 4 | 
            +
              def on_action
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
            end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            KManager.opts.app_name                    = 'KDomain Generator'
         | 
| 9 | 
            +
            KManager.opts.sleep                       = 5
         | 
| 10 | 
            +
            KManager.opts.reboot_on_kill              = 0
         | 
| 11 | 
            +
            KManager.opts.reboot_sleep                = 4
         | 
| 12 | 
            +
            KManager.opts.exception_style             = :short
         | 
| 13 | 
            +
            KManager.opts.show.time_taken             = true
         | 
| 14 | 
            +
            KManager.opts.show.finished               = true
         | 
| 15 | 
            +
            KManager.opts.show.finished_message       = 'FINISHED :)'
         | 
| 16 | 
            +
             | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/Guardfile
    CHANGED
    
    | @@ -19,6 +19,7 @@ group :green_pass_then_cop, halt_on_fail: true do | |
| 19 19 | 
             
                # Ruby files
         | 
| 20 20 | 
             
                ruby = dsl.ruby
         | 
| 21 21 | 
             
                dsl.watch_spec_files_for(ruby.lib_files)
         | 
| 22 | 
            +
                watch(%r{^lib/k_domain/domain_model/transform_steps/(.+).rb}) { 'spec/k_domain/domain_model/transform_spec.rb' }
         | 
| 22 23 | 
             
                watch(%r{^lib/k_domain/**/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
         | 
| 23 24 | 
             
                watch(%r{^lib/k_domain/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
         | 
| 24 25 | 
             
              end
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,3 +1,18 @@ | |
| 1 | 
            +
            # JSON Schema
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            The following schemas were created using the following processes.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ```
         | 
| 6 | 
            +
            quicktype -o json-schema/database.json -t database -l schema spec/sample_output/printspeak/schema.json
         | 
| 7 | 
            +
            quicktype -o json-schema/database.rb   -t database -l ruby   json-schema/database-altered.json
         | 
| 8 | 
            +
            spec/sample_output/printspeak/schema.json
         | 
| 9 | 
            +
            json-schema/database-altered.json
         | 
| 10 | 
            +
            ```
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            remove statistics
         | 
| 13 | 
            +
            remove (or move rails structure)
         | 
| 14 | 
            +
            drop erd_location
         | 
| 15 | 
            +
             | 
| 1 16 | 
             
            # K Domain
         | 
| 2 17 |  | 
| 3 18 | 
             
            > K Domain builds complex domain schemas by combining the database schema with a rich entity relationship DSLs
         | 
    
        data/STORIES.md
    CHANGED
    
    | @@ -16,25 +16,54 @@ As a Developer, I can customize domain configuration, so that I can have opinion | |
| 16 16 |  | 
| 17 17 | 
             
            - Handle traits
         | 
| 18 18 |  | 
| 19 | 
            +
            ### Tasks next on list
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            BUGs in domain_model load
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            - spec/k_domain/domain_model/load_spec.rb:135
         | 
| 24 | 
            +
            - FIXED: module_name should be empty
         | 
| 25 | 
            +
            - FIXED: name mismatch (attr_accessor, attr_reader, attr_writer) in behaviours vs in (attr_accessors, attr_readers, attr_writers) functions
         | 
| 26 | 
            +
            - functions - (attr_accessors, attr_readers, attr_writers) are all empty
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            External ruby process - ShimLoading and ExtractModel
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            - You need a clear memory foot print for shim loading and model extraction, best to run these from inside a new ruby process
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            Log Warning to Investigate Issues
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            - FIXED: All the logged warnings in k_domain need to turn up in on the investigate issues register
         | 
| 35 | 
            +
            - Investigate needs a debug flag that when turned on, will write the issues to the console
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            Print progress dot
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            - Make this configurable
         | 
| 40 | 
            +
            - Decide what steps this should run for
         | 
| 41 | 
            +
            - Show step label via configuration
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            ## Stories and tasks
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            ### Stories - completed
         | 
| 46 | 
            +
             | 
| 19 47 | 
             
            As a Developer, I can read native rails model data, so that I can leverage existing rails applications for ERD modeling
         | 
| 20 48 |  | 
| 49 | 
            +
            - Proof of concept
         | 
| 21 50 | 
             
            - Use Meta Programming and re-implement ActiveRecord::Base
         | 
| 22 51 |  | 
| 23 | 
            -
            ### Tasks  | 
| 52 | 
            +
            ### Tasks - completed
         | 
| 24 53 |  | 
| 25 54 | 
             
            Refactor / Simply
         | 
| 26 55 |  | 
| 27 | 
            -
            - Replace complex objects  | 
| 56 | 
            +
            - Replace complex objects with structs for ancillary data structures such as investigate
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            Steps to support write methods on base class
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            - Simplify lib/k_domain/domain_model/transform.rb
         | 
| 28 61 |  | 
| 29 62 | 
             
            User acceptance testing
         | 
| 30 63 |  | 
| 31 64 | 
             
            - Provide sample printers for each data structure to visually check data is loading
         | 
| 32 65 | 
             
            - Point raw_db_schema loader towards a complex ERD and check how it performs
         | 
| 33 66 |  | 
| 34 | 
            -
            ## Stories and tasks
         | 
| 35 | 
            -
             | 
| 36 | 
            -
            ### Tasks - completed
         | 
| 37 | 
            -
             | 
| 38 67 | 
             
            Setup RubyGems and RubyDoc
         | 
| 39 68 |  | 
| 40 69 | 
             
            - Build and deploy gem to [rubygems.org](https://rubygems.org/gems/k_domain)
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # Usage: include KDomain::Config::
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module KDomain
         | 
| 6 | 
            +
              module Config
         | 
| 7 | 
            +
                def configuration
         | 
| 8 | 
            +
                  @configuration ||= KDomain::Config::Configuration.new
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def reset
         | 
| 12 | 
            +
                  @configuration = KDomain::Config::Configuration.new
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def configure
         | 
| 16 | 
            +
                  yield(configuration)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KDomain
         | 
| 4 | 
            +
              module Config
         | 
| 5 | 
            +
                # Configuration object for Domain Configuration
         | 
| 6 | 
            +
                class Configuration
         | 
| 7 | 
            +
                  include KLog::Logging
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  ConfigModel = Struct.new(:name, :main_key, :traits)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  attr_accessor :default_main_key
         | 
| 12 | 
            +
                  attr_accessor :default_traits
         | 
| 13 | 
            +
                  attr_accessor :fallback_keys
         | 
| 14 | 
            +
                  attr_accessor :models
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def initialize
         | 
| 17 | 
            +
                    @default_main_key = nil
         | 
| 18 | 
            +
                    @default_traits = %i[trait1 trait2 trait3]
         | 
| 19 | 
            +
                    @fallback_keys = %i[]
         | 
| 20 | 
            +
                    @models = []
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  def model(name, main_key: nil, traits: nil)
         | 
| 24 | 
            +
                    @models << new_config_model(
         | 
| 25 | 
            +
                      name,
         | 
| 26 | 
            +
                      main_key: main_key || default_main_key,
         | 
| 27 | 
            +
                      traits: traits || default_traits
         | 
| 28 | 
            +
                    )
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  def find_model(table_name)
         | 
| 32 | 
            +
                    @find_model ||= Hash.new do |h, key|
         | 
| 33 | 
            +
                      h[key] = begin
         | 
| 34 | 
            +
                        entity = models.find { |e| e.name == key }
         | 
| 35 | 
            +
                        entity ||= new_config_model(key)
         | 
| 36 | 
            +
                        entity
         | 
| 37 | 
            +
                      end
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    @find_model[table_name]
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  def fallback_key(columns)
         | 
| 44 | 
            +
                    column_names = columns.each_with_object({}) do |column, hash|
         | 
| 45 | 
            +
                      hash[column.name.to_sym] = column.name.to_sym
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    fallback_keys.find { |key| column_names.key?(key) }
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  def debug(heading: 'Domain configuration')
         | 
| 52 | 
            +
                    log.structure(to_h, title: heading) # , line_width: 150, formatter: formatter)
         | 
| 53 | 
            +
                    ''
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  def to_h
         | 
| 57 | 
            +
                    {
         | 
| 58 | 
            +
                      default_main_key: default_main_key,
         | 
| 59 | 
            +
                      default_traits: default_traits,
         | 
| 60 | 
            +
                      fallback_keys: fallback_keys,
         | 
| 61 | 
            +
                      models: models.map(&:to_h)
         | 
| 62 | 
            +
                    }
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  private
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                  def new_config_model(name, main_key: nil, traits: nil)
         | 
| 68 | 
            +
                    ConfigModel.new(
         | 
| 69 | 
            +
                      name,
         | 
| 70 | 
            +
                      main_key || default_main_key,
         | 
| 71 | 
            +
                      traits || default_traits
         | 
| 72 | 
            +
                    )
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
| @@ -23,6 +23,8 @@ module KDomain | |
| 23 23 | 
             
                    @raw_data = KUtil.data.json_parse(json, as: :hash_symbolized)
         | 
| 24 24 |  | 
| 25 25 | 
             
                    @data = KDomain::Schemas::DomainModel.new(@raw_data)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    enrichment
         | 
| 26 28 | 
             
                  end
         | 
| 27 29 |  | 
| 28 30 | 
             
                  def to_h
         | 
| @@ -30,6 +32,45 @@ module KDomain | |
| 30 32 |  | 
| 31 33 | 
             
                    @raw_data
         | 
| 32 34 | 
             
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  private
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  def enrichment
         | 
| 39 | 
            +
                    attach_rails_model_to_domain_model
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  def attach_rails_model_to_domain_model
         | 
| 43 | 
            +
                    @data.domain.models.each do |domain_model|
         | 
| 44 | 
            +
                      domain_model.rails_model = @data.rails_structure.find_model(domain_model.name)
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                      if domain_model.rails_model
         | 
| 47 | 
            +
                        attach_column_relations(domain_model)
         | 
| 48 | 
            +
                      else
         | 
| 49 | 
            +
                        log.error("Rails Model not found for #{domain_model.name}") unless domain_model.rails_model
         | 
| 50 | 
            +
                      end
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def attach_column_relations(domain_model)
         | 
| 55 | 
            +
                    domain_model.columns.each do |column|
         | 
| 56 | 
            +
                      column.relationships = []
         | 
| 57 | 
            +
                      add_column_relations(domain_model.rails_model, column, :belongs_to)
         | 
| 58 | 
            +
                      add_column_relations(domain_model.rails_model, column, :has_one)
         | 
| 59 | 
            +
                      add_column_relations(domain_model.rails_model, column, :has_many)
         | 
| 60 | 
            +
                      add_column_relations(domain_model.rails_model, column, :has_and_belongs_to_many)
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def add_column_relations(rails_model, column, relation_type)
         | 
| 65 | 
            +
                    relations = rails_model.behaviours.send(relation_type)
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    return if relations.nil?
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                    relations = relations.map { |relation| { relation_type: relation_type }.merge(relation.to_h) }
         | 
| 70 | 
            +
                    relations.select { |relation| column[:name] == relation.dig(:opts, :foreign_key) }.each do |relation|
         | 
| 71 | 
            +
                      column.relationships << KDomain::Schemas::Domain::Model::Relationship.new(relation)
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
                  end
         | 
| 33 74 | 
             
                end
         | 
| 34 75 | 
             
              end
         | 
| 35 76 | 
             
            end
         | 
| @@ -11,25 +11,34 @@ module KDomain | |
| 11 11 | 
             
                  attr_reader :db_schema
         | 
| 12 12 | 
             
                  attr_reader :target_step_file
         | 
| 13 13 | 
             
                  attr_reader :target_file
         | 
| 14 | 
            -
                  attr_reader : | 
| 14 | 
            +
                  attr_reader :model_path
         | 
| 15 | 
            +
                  attr_reader :controller_path
         | 
| 16 | 
            +
                  attr_reader :route_path
         | 
| 17 | 
            +
                  attr_reader :shim_loader
         | 
| 15 18 |  | 
| 16 | 
            -
                   | 
| 19 | 
            +
                  # rubocop:disable Metrics/ParameterLists
         | 
| 20 | 
            +
                  def initialize(db_schema: , target_file: , target_step_file: , model_path:, route_path:, controller_path:, shim_loader: nil)
         | 
| 17 21 | 
             
                    @db_schema        = db_schema
         | 
| 18 22 | 
             
                    @target_step_file = target_step_file
         | 
| 19 23 | 
             
                    @target_file      = target_file
         | 
| 20 | 
            -
                    @ | 
| 24 | 
            +
                    @model_path       = model_path
         | 
| 25 | 
            +
                    @controller_path  = controller_path
         | 
| 26 | 
            +
                    @route_path       = route_path
         | 
| 27 | 
            +
                    @shim_loader      = shim_loader
         | 
| 21 28 | 
             
                  end
         | 
| 29 | 
            +
                  # rubocop:enable Metrics/ParameterLists
         | 
| 22 30 |  | 
| 23 31 | 
             
                  # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
         | 
| 24 32 | 
             
                  def call
         | 
| 25 33 | 
             
                    valid = true
         | 
| 26 | 
            -
                    valid &&=  | 
| 27 | 
            -
                    valid &&=  | 
| 28 | 
            -
                    valid &&=  | 
| 29 | 
            -
                    valid &&=  | 
| 30 | 
            -
                    valid &&=  | 
| 31 | 
            -
                    valid &&=  | 
| 32 | 
            -
                    valid &&=  | 
| 34 | 
            +
                    valid &&= Step1DbSchema.run(domain_data, db_schema: db_schema, step_file: step_file('01-db-schema'))
         | 
| 35 | 
            +
                    valid &&= Step2DomainModels.run(domain_data, model_path: model_path, step_file: step_file('02-domain-model'))
         | 
| 36 | 
            +
                    valid &&= Step4RailsResourceModels.run(domain_data, model_path: model_path, step_file: step_file('04-rails-resource-models'))
         | 
| 37 | 
            +
                    valid &&= Step5RailsResourceRoutes.run(domain_data, route_path: route_path, controller_path: controller_path, step_file: step_file('05-rails-resource-routes'))
         | 
| 38 | 
            +
                    valid &&= Step6RailsStructureModels.run(domain_data, model_path: model_path, step_file: step_file('06-rails-structure-models'), shim_loader: shim_loader)
         | 
| 39 | 
            +
                    valid &&= Step7RailsStructureControllers.run(domain_data, controller_path: controller_path, step_file: step_file('07-rails-structure-controllers'), shim_loader: shim_loader)
         | 
| 40 | 
            +
                    valid &&= Step8DomainColumns.run(domain_data, step_file: step_file('08-domain-columns'))
         | 
| 41 | 
            +
                    valid &&= Step20Dictionary.run(domain_data, step_file: step_file('20-dictionary'))
         | 
| 33 42 |  | 
| 34 43 | 
             
                    raise 'DomainModal transform failed' unless valid
         | 
| 35 44 |  | 
| @@ -39,49 +48,13 @@ module KDomain | |
| 39 48 | 
             
                  end
         | 
| 40 49 | 
             
                  # rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
         | 
| 41 50 |  | 
| 42 | 
            -
                  def  | 
| 43 | 
            -
                     | 
| 44 | 
            -
                    write(step: '1-attach-db-schema')
         | 
| 51 | 
            +
                  def step_file(step_name)
         | 
| 52 | 
            +
                    format(target_step_file, step: step_name)
         | 
| 45 53 | 
             
                  end
         | 
| 46 54 |  | 
| 47 | 
            -
                  def  | 
| 48 | 
            -
                     | 
| 49 | 
            -
                    write( | 
| 50 | 
            -
                  end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                  def step3
         | 
| 53 | 
            -
                    Step3AttachColumns.run(domain_data)
         | 
| 54 | 
            -
                    write(step: '3-attach-columns')
         | 
| 55 | 
            -
                  end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                  def step4
         | 
| 58 | 
            -
                    Step4AttachErdFiles.run(domain_data, erd_path: erd_path)
         | 
| 59 | 
            -
                    write(step: '4-attach-erd-files')
         | 
| 60 | 
            -
                  end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                  def step5
         | 
| 63 | 
            -
                    Step5AttachDictionary.run(domain_data, erd_path: erd_path)
         | 
| 64 | 
            -
                    write(step: '5-attach-dictionary')
         | 
| 65 | 
            -
                  end
         | 
| 66 | 
            -
             | 
| 67 | 
            -
                  def step8
         | 
| 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')
         | 
| 75 | 
            -
                  end
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                  def write(step: nil)
         | 
| 78 | 
            -
                    file = if step.nil?
         | 
| 79 | 
            -
                             target_file
         | 
| 80 | 
            -
                           else
         | 
| 81 | 
            -
                             format(target_step_file, step: step)
         | 
| 82 | 
            -
                           end
         | 
| 83 | 
            -
                    FileUtils.mkdir_p(File.dirname(file))
         | 
| 84 | 
            -
                    File.write(file, JSON.pretty_generate(domain_data))
         | 
| 55 | 
            +
                  def write
         | 
| 56 | 
            +
                    FileUtils.mkdir_p(File.dirname(target_file))
         | 
| 57 | 
            +
                    File.write(target_file, JSON.pretty_generate(domain_data))
         | 
| 85 58 | 
             
                  end
         | 
| 86 59 |  | 
| 87 60 | 
             
                  # rubocop:disable Metrics/MethodLength
         | 
| @@ -89,12 +62,11 @@ module KDomain | |
| 89 62 | 
             
                    # The initial domain model structure is created here, but populated during the workflows.
         | 
| 90 63 | 
             
                    @domain_data ||= {
         | 
| 91 64 | 
             
                      domain: {
         | 
| 92 | 
            -
                        models: [] | 
| 93 | 
            -
                        erd_files: []
         | 
| 65 | 
            +
                        models: []
         | 
| 94 66 | 
             
                      },
         | 
| 95 67 | 
             
                      rails_resource: {
         | 
| 96 68 | 
             
                        models: [],
         | 
| 97 | 
            -
                         | 
| 69 | 
            +
                        routes: []
         | 
| 98 70 | 
             
                      },
         | 
| 99 71 | 
             
                      rails_structure: {
         | 
| 100 72 | 
             
                        models: [],
         | 
| @@ -107,6 +79,7 @@ module KDomain | |
| 107 79 | 
             
                        tables: [],
         | 
| 108 80 | 
             
                        indexes: [],
         | 
| 109 81 | 
             
                        foreign_keys: [],
         | 
| 82 | 
            +
                        views: [],
         | 
| 110 83 | 
             
                        meta: {}
         | 
| 111 84 | 
             
                      },
         | 
| 112 85 | 
             
                      investigate: {
         | 
| @@ -114,7 +87,6 @@ module KDomain | |
| 114 87 | 
             
                      }
         | 
| 115 88 | 
             
                    }
         | 
| 116 89 | 
             
                  end
         | 
| 117 | 
            -
             | 
| 118 90 | 
             
                  # rubocop:enable Metrics/MethodLength
         | 
| 119 91 | 
             
                end
         | 
| 120 92 | 
             
              end
         | 
| @@ -2,10 +2,11 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            # The require order is important due to dependencies
         | 
| 4 4 | 
             
            require_relative './step'
         | 
| 5 | 
            -
            require_relative './ | 
| 6 | 
            -
            require_relative './ | 
| 7 | 
            -
            require_relative './ | 
| 8 | 
            -
            require_relative './ | 
| 9 | 
            -
            require_relative './ | 
| 10 | 
            -
            require_relative './ | 
| 11 | 
            -
            require_relative './ | 
| 5 | 
            +
            require_relative './step1_db_schema'
         | 
| 6 | 
            +
            require_relative './step2_domain_models'
         | 
| 7 | 
            +
            require_relative './step4_rails_resource_models'
         | 
| 8 | 
            +
            require_relative './step5_rails_resource_routes'
         | 
| 9 | 
            +
            require_relative './step6_rails_structure_models'
         | 
| 10 | 
            +
            require_relative './step7_rails_structure_controllers'
         | 
| 11 | 
            +
            require_relative './step8_domain_columns'
         | 
| 12 | 
            +
            require_relative './step20_dictionary'
         | 
| @@ -24,7 +24,8 @@ module KDomain | |
| 24 24 | 
             
                  def self.run(domain_data, **opts)
         | 
| 25 25 | 
             
                    step = new(domain_data, **opts)
         | 
| 26 26 | 
             
                    step.call
         | 
| 27 | 
            -
                    step
         | 
| 27 | 
            +
                    step.write(opts[:step_file])
         | 
| 28 | 
            +
                    step.valid?
         | 
| 28 29 | 
             
                  end
         | 
| 29 30 |  | 
| 30 31 | 
             
                  def guard(message)
         | 
| @@ -32,6 +33,15 @@ module KDomain | |
| 32 33 | 
             
                    @valid = false
         | 
| 33 34 | 
             
                  end
         | 
| 34 35 |  | 
| 36 | 
            +
                  def warning(message)
         | 
| 37 | 
            +
                    log.warn message
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def write(file)
         | 
| 41 | 
            +
                    FileUtils.mkdir_p(File.dirname(file))
         | 
| 42 | 
            +
                    File.write(file, JSON.pretty_generate(domain_data))
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 35 45 | 
             
                  # Domain Model Accessor/Helpers
         | 
| 36 46 | 
             
                  def domain
         | 
| 37 47 | 
             
                    guard('domain is missing') if domain_data[:domain].nil?
         | 
| @@ -58,6 +68,14 @@ module KDomain | |
| 58 68 | 
             
                    rails_resource[:models] = value
         | 
| 59 69 | 
             
                  end
         | 
| 60 70 |  | 
| 71 | 
            +
                  def rails_resource_routes
         | 
| 72 | 
            +
                    rails_resource[:routes]
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  def rails_resource_routes=(value)
         | 
| 76 | 
            +
                    rails_resource[:routes] = value
         | 
| 77 | 
            +
                  end
         | 
| 78 | 
            +
             | 
| 61 79 | 
             
                  def rails_resource_controllers
         | 
| 62 80 | 
             
                    rails_resource[:controllers]
         | 
| 63 81 | 
             
                  end
         | 
| @@ -73,6 +91,10 @@ module KDomain | |
| 73 91 | 
             
                    rails_structure[:models]
         | 
| 74 92 | 
             
                  end
         | 
| 75 93 |  | 
| 94 | 
            +
                  def find_rails_structure_models(model_name)
         | 
| 95 | 
            +
                    rails_structure_models.find { |model| model[:model_name] == model_name }
         | 
| 96 | 
            +
                  end
         | 
| 97 | 
            +
             | 
| 76 98 | 
             
                  def rails_structure_models=(value)
         | 
| 77 99 | 
             
                    rails_structure[:models] = value
         | 
| 78 100 | 
             
                  end
         | 
| @@ -81,6 +103,10 @@ module KDomain | |
| 81 103 | 
             
                    rails_structure[:controllers]
         | 
| 82 104 | 
             
                  end
         | 
| 83 105 |  | 
| 106 | 
            +
                  def rails_structure_controllers=(value)
         | 
| 107 | 
            +
                    rails_structure[:controllers] = value
         | 
| 108 | 
            +
                  end
         | 
| 109 | 
            +
             | 
| 84 110 | 
             
                  # Database Accessor/Helpers
         | 
| 85 111 | 
             
                  def database=(value)
         | 
| 86 112 | 
             
                    domain_data[:database] = value
         | 
    
        data/lib/k_domain/domain_model/transform_steps/{step1_attach_db_schema.rb → step1_db_schema.rb}
    RENAMED
    
    | @@ -2,12 +2,13 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            module KDomain
         | 
| 4 4 | 
             
              module DomainModel
         | 
| 5 | 
            -
                class  | 
| 5 | 
            +
                class Step1DbSchema < KDomain::DomainModel::Step
         | 
| 6 6 | 
             
                  # Map database schema to domain model
         | 
| 7 7 | 
             
                  def call
         | 
| 8 8 | 
             
                    raise 'Schema not supplied' if opts[:db_schema].nil?
         | 
| 9 9 |  | 
| 10 10 | 
             
                    self.database = opts[:db_schema].clone
         | 
| 11 | 
            +
                    database[:tables] = database[:tables] # .take(10) # .slice(156, 1)
         | 
| 11 12 |  | 
| 12 13 | 
             
                    guard('tables are missing')               if database[:tables].nil?
         | 
| 13 14 | 
             
                    guard('indexes are missing')              if database[:indexes].nil?
         | 
    
        data/lib/k_domain/domain_model/transform_steps/{step5_attach_dictionary.rb → step20_dictionary.rb}
    RENAMED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            # | 
| 4 | 
            -
            class  | 
| 3 | 
            +
            #  data dictionary
         | 
| 4 | 
            +
            class Step20Dictionary < KDomain::DomainModel::Step
         | 
| 5 5 | 
             
              attr_reader :dictionary
         | 
| 6 6 |  | 
| 7 7 | 
             
              def call
         | 
| @@ -27,8 +27,11 @@ 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 | 
            -
                     | 
| 31 | 
            -
             | 
| 30 | 
            +
                    investigate(step: :step5_dictionary,
         | 
| 31 | 
            +
                                location: :process,
         | 
| 32 | 
            +
                                key: "#{model_name},#{column_name},#{column_type}",
         | 
| 33 | 
            +
                                message: "#{model_name} has a type mismatch for column name: #{column_name}")
         | 
| 34 | 
            +
             | 
| 32 35 | 
             
                    entry[:types] << column_type
         | 
| 33 36 | 
             
                    entry[:type_count] = entry[:type_count] + 1
         | 
| 34 37 | 
             
                  end
         |