Class: KDomain::Schemas::Domain::Model
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- KDomain::Schemas::Domain::Model
show all
- Defined in:
- lib/k_domain/schemas/domain.rb
Defined Under Namespace
Classes: Column, Pk, Relationship
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#rails_model ⇒ Object
Link <KDomain::Schemas::RailsStructure::Model> to the domain model
109
110
111
|
# File 'lib/k_domain/schemas/domain.rb', line 109
def rails_model
@rails_model
end
|
Instance Method Details
#columns_data ⇒ Object
139
140
141
|
# File 'lib/k_domain/schemas/domain.rb', line 139
def columns_data
@columns_data ||= columns_for_structure_types(:data)
end
|
#columns_data_foreign ⇒ Object
Also known as:
rows_fields_and_fk
168
169
170
|
# File 'lib/k_domain/schemas/domain.rb', line 168
def columns_data_foreign
@columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key, :foreign_type)
end
|
#columns_data_foreign_virtual ⇒ Object
183
184
185
|
# File 'lib/k_domain/schemas/domain.rb', line 183
def columns_data_foreign_virtual
@columns_data_foreign_virtual ||= columns_for_structure_types(:data, :foreign_key, :foreign_type, :timestamp, :deleted_at)
end
|
#columns_data_primary ⇒ Object
Also known as:
rows_fields_and_pk
173
174
175
|
# File 'lib/k_domain/schemas/domain.rb', line 173
def columns_data_primary
@columns_data_primary ||= columns_for_structure_types(:data, :primary_key)
end
|
#columns_data_virtual ⇒ Object
Also known as:
rows_fields_and_virtual
178
179
180
|
# File 'lib/k_domain/schemas/domain.rb', line 178
def columns_data_virtual
@columns_data_virtual ||= columns_for_structure_types(:data, :foreign_type, :timestamp, :deleted_at)
end
|
#columns_deleted_at ⇒ Object
160
161
162
|
# File 'lib/k_domain/schemas/domain.rb', line 160
def columns_deleted_at
@columns_data_deleted_at ||= columns_for_structure_types(:deleted_at)
end
|
#columns_foreign_key ⇒ Object
147
148
149
|
# File 'lib/k_domain/schemas/domain.rb', line 147
def columns_foreign_key
@columns_foreign ||= columns_for_structure_types(:foreign_key)
end
|
#columns_foreign_type ⇒ Object
152
153
154
|
# File 'lib/k_domain/schemas/domain.rb', line 152
def columns_foreign_type
@columns_foreign_type ||= columns_for_structure_types(:foreign_type)
end
|
#columns_primary ⇒ Object
143
144
145
|
# File 'lib/k_domain/schemas/domain.rb', line 143
def columns_primary
@columns_primary ||= columns_for_structure_types(:primary_key)
end
|
#columns_timestamp ⇒ Object
156
157
158
|
# File 'lib/k_domain/schemas/domain.rb', line 156
def columns_timestamp
@columns_data_timestamp ||= columns_for_structure_types(:timestamp)
end
|
#columns_virtual ⇒ Object
164
165
166
|
# File 'lib/k_domain/schemas/domain.rb', line 164
def columns_virtual
@columns_virtual ||= columns_for_structure_types(:foreign_type, :timestamp, :deleted_at)
end
|
#config ⇒ Object
Custom model configurations such as main_key and traits
126
127
128
|
# File 'lib/k_domain/schemas/domain.rb', line 126
def config
@config ||= KDomain.configuration.find_model(name.to_sym)
end
|
#create_update_timestamp? ⇒ Boolean
119
120
121
122
123
|
# File 'lib/k_domain/schemas/domain.rb', line 119
def create_update_timestamp?
names = columns_timestamp.map(&:name)
(names & %w[created_at updated_at]).any?
end
|
#main_key ⇒ Object
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
131
132
133
|
# File 'lib/k_domain/schemas/domain.rb', line 131
def main_key
@main_key ||= config.main_key || KDomain.configuration.fallback_key(columns_data)
end
|
#pk? ⇒ Boolean
115
116
117
|
# File 'lib/k_domain/schemas/domain.rb', line 115
def pk?
pk.exist
end
|
#ruby? ⇒ Boolean
111
112
113
|
# File 'lib/k_domain/schemas/domain.rb', line 111
def ruby?
file && File.exist?(file)
end
|
#traits ⇒ Object
135
136
137
|
# File 'lib/k_domain/schemas/domain.rb', line 135
def traits
config.traits
end
|