Class: KDomain::DomainModel::Step
- Inherits:
-
Object
- Object
- KDomain::DomainModel::Step
show all
- Includes:
- KLog::Logging
- Defined in:
- lib/k_domain/domain_model/transform_steps/step.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(domain_data, **opts) ⇒ Step
Returns a new instance of Step.
13
14
15
16
17
18
19
20
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 13
def initialize(domain_data, **opts)
@domain_data = domain_data
@opts = opts
@valid = true
end
|
Instance Attribute Details
#domain_data ⇒ Object
Returns the value of attribute domain_data.
8
9
10
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 8
def domain_data
@domain_data
end
|
#opts ⇒ Object
Returns the value of attribute opts.
9
10
11
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 9
def opts
@opts
end
|
#valid ⇒ Object
Also known as:
valid?
Returns the value of attribute valid.
10
11
12
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 10
def valid
@valid
end
|
Class Method Details
.run(domain_data, **opts) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 28
def self.run(domain_data, **opts)
step = new(domain_data, **opts)
step.call
step.write(opts[:step_file])
step.valid?
end
|
Instance Method Details
#call ⇒ Object
26
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 26
def call; end
|
#camel(value) ⇒ Object
22
23
24
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 22
def camel(value)
Cmdlet::Case::Camel.new.call(value)
end
|
#database ⇒ Object
119
120
121
122
123
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 119
def database
guard('database is missing') if domain_data[:database].nil?
domain_data[:database]
end
|
#database=(value) ⇒ Object
Database Accessor/Helpers
115
116
117
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 115
def database=(value)
domain_data[:database] = value
end
|
#database_foreign_keys ⇒ Object
131
132
133
134
135
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 131
def database_foreign_keys
guard('database_foreign_keys is missing') if database[:foreign_keys].nil?
database[:foreign_keys]
end
|
#database_tables ⇒ Object
125
126
127
128
129
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 125
def database_tables
guard('database_tables is missing') if database[:tables].nil?
database[:tables]
end
|
#domain ⇒ Object
Domain Model Accessor/Helpers
50
51
52
53
54
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 50
def domain
guard('domain is missing') if domain_data[:domain].nil?
domain_data[:domain]
end
|
#domain_models ⇒ Object
56
57
58
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 56
def domain_models
domain[:models]
end
|
#find_foreign_table(lhs_table_name, column_name) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 149
def find_foreign_table(lhs_table_name, column_name)
fk = database_foreign_keys.find { |foreign_key| foreign_key[:left] == lhs_table_name && foreign_key[:column] == column_name }
return fk[:right] if fk
nil
end
|
#find_rails_structure_models(model_name) ⇒ Object
98
99
100
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 98
def find_rails_structure_models(model_name)
rails_structure_models.find { |model| model[:model_name] == model_name }
end
|
#find_table_for_model(model) ⇒ Object
137
138
139
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 137
def find_table_for_model(model)
database_tables.find { |table| table[:name] == model[:table_name] }
end
|
#guard(message) ⇒ Object
35
36
37
38
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 35
def guard(message)
log.error message
@valid = false
end
|
#investigate(step:, location:, key:, message:) ⇒ Object
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 156
def investigate(step:, location:, key:, message:)
unique_key = build_key(step, location, key)
return if issue_hash.key?(unique_key)
value = { step: step, location: location, key: key, message: message }
issues << value issue_hash[unique_key] = value end
|
#issues ⇒ Object
167
168
169
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 167
def issues
domain_data[:investigate][:issues]
end
|
#rails_resource ⇒ Object
Rails Resource File Accessor/Helpers
61
62
63
64
65
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 61
def rails_resource
guard('rails_resource is missing') if domain_data[:rails_resource].nil?
domain_data[:rails_resource]
end
|
#rails_resource_controllers ⇒ Object
83
84
85
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 83
def rails_resource_controllers
rails_resource[:controllers]
end
|
#rails_resource_models ⇒ Object
67
68
69
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 67
def rails_resource_models
rails_resource[:models]
end
|
#rails_resource_models=(value) ⇒ Object
71
72
73
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 71
def rails_resource_models=(value)
rails_resource[:models] = value
end
|
#rails_resource_routes ⇒ Object
75
76
77
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 75
def rails_resource_routes
rails_resource[:routes]
end
|
#rails_resource_routes=(value) ⇒ Object
79
80
81
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 79
def rails_resource_routes=(value)
rails_resource[:routes] = value
end
|
#rails_structure ⇒ Object
Rails Structure File Accessor/Helpers
88
89
90
91
92
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 88
def rails_structure
guard('rails_structure is missing') if domain_data[:rails_structure].nil?
domain_data[:rails_structure]
end
|
#rails_structure_controllers ⇒ Object
106
107
108
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 106
def rails_structure_controllers
rails_structure[:controllers]
end
|
#rails_structure_controllers=(value) ⇒ Object
110
111
112
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 110
def rails_structure_controllers=(value)
rails_structure[:controllers] = value
end
|
#rails_structure_models ⇒ Object
94
95
96
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 94
def rails_structure_models
rails_structure[:models]
end
|
#rails_structure_models=(value) ⇒ Object
102
103
104
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 102
def rails_structure_models=(value)
rails_structure[:models] = value
end
|
#table_name_exist?(table_name) ⇒ Boolean
141
142
143
144
145
146
147
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 141
def table_name_exist?(table_name)
if table_name.nil?
guard('table_name_exist? was provided with a table_name: nil')
return false
end
database_table_name_hash.key?(table_name)
end
|
#warning(message) ⇒ Object
40
41
42
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 40
def warning(message)
log.warn message
end
|
#write(file) ⇒ Object
44
45
46
47
|
# File 'lib/k_domain/domain_model/transform_steps/step.rb', line 44
def write(file)
FileUtils.mkdir_p(File.dirname(file))
File.write(file, JSON.pretty_generate(domain_data))
end
|