Class: KDomain::DomainModel::Transform
- Inherits:
-
Object
- Object
- KDomain::DomainModel::Transform
- Includes:
- KLog::Logging
- Defined in:
- lib/k_domain/domain_model/transform.rb
Instance Attribute Summary collapse
-
#controller_path ⇒ Object
readonly
Returns the value of attribute controller_path.
-
#controller_shim_loader ⇒ Object
readonly
Returns the value of attribute controller_shim_loader.
-
#db_schema ⇒ Object
readonly
Returns the value of attribute db_schema.
-
#model_path ⇒ Object
readonly
Returns the value of attribute model_path.
-
#model_shim_loader ⇒ Object
readonly
Returns the value of attribute model_shim_loader.
-
#route_path ⇒ Object
readonly
Returns the value of attribute route_path.
-
#target_file ⇒ Object
readonly
Returns the value of attribute target_file.
-
#target_step_file ⇒ Object
readonly
Returns the value of attribute target_step_file.
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity.
-
#domain_data ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(db_schema:, target_file:, target_step_file:, model_path:, route_path:, controller_path:, model_shim_loader: nil, controller_shim_loader: nil) ⇒ Transform
constructor
rubocop:disable Metrics/ParameterLists.
-
#step_file(step_name) ⇒ Object
rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity.
- #write ⇒ Object
Constructor Details
#initialize(db_schema:, target_file:, target_step_file:, model_path:, route_path:, controller_path:, model_shim_loader: nil, controller_shim_loader: nil) ⇒ Transform
rubocop:disable Metrics/ParameterLists
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/k_domain/domain_model/transform.rb', line 21 def initialize(db_schema: , target_file: , target_step_file: , model_path:, route_path:, controller_path:, model_shim_loader: nil, controller_shim_loader: nil) @db_schema = db_schema @target_step_file = target_step_file @target_file = target_file @model_path = model_path @controller_path = controller_path @route_path = route_path @model_shim_loader = model_shim_loader @controller_shim_loader = controller_shim_loader end |
Instance Attribute Details
#controller_path ⇒ Object (readonly)
Returns the value of attribute controller_path.
15 16 17 |
# File 'lib/k_domain/domain_model/transform.rb', line 15 def controller_path @controller_path end |
#controller_shim_loader ⇒ Object (readonly)
Returns the value of attribute controller_shim_loader.
18 19 20 |
# File 'lib/k_domain/domain_model/transform.rb', line 18 def controller_shim_loader @controller_shim_loader end |
#db_schema ⇒ Object (readonly)
Returns the value of attribute db_schema.
11 12 13 |
# File 'lib/k_domain/domain_model/transform.rb', line 11 def db_schema @db_schema end |
#model_path ⇒ Object (readonly)
Returns the value of attribute model_path.
14 15 16 |
# File 'lib/k_domain/domain_model/transform.rb', line 14 def model_path @model_path end |
#model_shim_loader ⇒ Object (readonly)
Returns the value of attribute model_shim_loader.
17 18 19 |
# File 'lib/k_domain/domain_model/transform.rb', line 17 def model_shim_loader @model_shim_loader end |
#route_path ⇒ Object (readonly)
Returns the value of attribute route_path.
16 17 18 |
# File 'lib/k_domain/domain_model/transform.rb', line 16 def route_path @route_path end |
#target_file ⇒ Object (readonly)
Returns the value of attribute target_file.
13 14 15 |
# File 'lib/k_domain/domain_model/transform.rb', line 13 def target_file @target_file end |
#target_step_file ⇒ Object (readonly)
Returns the value of attribute target_step_file.
12 13 14 |
# File 'lib/k_domain/domain_model/transform.rb', line 12 def target_step_file @target_step_file end |
Instance Method Details
#call ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/k_domain/domain_model/transform.rb', line 34 def call valid = true valid &&= Step1DbSchema.run(domain_data, db_schema: db_schema, step_file: step_file('01-db-schema')) valid &&= Step2DomainModels.run(domain_data, model_path: model_path, step_file: step_file('02-domain-model')) valid &&= Step4RailsResourceModels.run(domain_data, model_path: model_path, step_file: step_file('04-rails-resource-models')) valid &&= Step5RailsResourceRoutes.run(domain_data, route_path: route_path, controller_path: controller_path, step_file: step_file('05-rails-resource-routes')) valid &&= Step6RailsStructureModels.run(domain_data, model_path: model_path, step_file: step_file('06-rails-structure-models'), shim_loader: model_shim_loader) valid &&= Step7RailsStructureControllers.run(domain_data, controller_path: controller_path, step_file: step_file('07-rails-structure-controllers'), shim_loader: controller_shim_loader) valid &&= Step8DomainColumns.run(domain_data, step_file: step_file('08-domain-columns')) valid &&= Step20Dictionary.run(domain_data, step_file: step_file('20-dictionary')) raise 'DomainModal transform failed' unless valid write nil end |
#domain_data ⇒ Object
rubocop:disable Metrics/MethodLength
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/k_domain/domain_model/transform.rb', line 63 def domain_data # The initial domain model structure is created here, but populated during the workflows. @domain_data ||= { domain: { models: [] }, rails_resource: { models: [], routes: [] }, rails_structure: { models: [], controllers: [] }, dictionary: { items: [] }, database: { tables: [], indexes: [], foreign_keys: [], views: [], meta: {} }, investigate: { issues: [] } } end |
#step_file(step_name) ⇒ Object
rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
53 54 55 |
# File 'lib/k_domain/domain_model/transform.rb', line 53 def step_file(step_name) format(target_step_file, step: step_name) end |
#write ⇒ Object
57 58 59 60 |
# File 'lib/k_domain/domain_model/transform.rb', line 57 def write FileUtils.mkdir_p(File.dirname(target_file)) File.write(target_file, JSON.pretty_generate(domain_data)) end |