Class: KDomain::DomainModel::Entity
- Inherits:
-
Object
- Object
- KDomain::DomainModel::Entity
- Defined in:
- lib/k_domain/schemas/domain/old/entity.rb
Instance Attribute Summary collapse
-
#belongs_to ⇒ Object
alias :name :student_name # not wrong, only for getter alias :name= :student_name= # add this for setter alias :name? :student_name? # add this for boolean.
-
#columns ⇒ Object
Model columns.
-
#force ⇒ Object
Currently only has the value :cascade.
-
#has_and_belongs_to_many ⇒ Object
Returns the value of attribute has_and_belongs_to_many.
-
#has_many ⇒ Object
Returns the value of attribute has_many.
-
#has_one ⇒ Object
Returns the value of attribute has_one.
- #id ⇒ Object
-
#main_key ⇒ Object
This entity has a main field that is useful for rendering and may be used for unique constraint, may also be called display_name.
-
#model_type ⇒ Object
Model type - :entity, :basic_user, :admin_user.
-
#name ⇒ Object
(also: #model_name)
Name of the entity model.
-
#name_plural ⇒ Object
(also: #names)
Name of the entity model in plural form.
-
#rails_model ⇒ Object
Returns the value of attribute rails_model.
-
#relations_one_to_one ⇒ Object
Model relationships - one_to_one, one_to_many and many_to_many.
-
#statistics ⇒ Object
Returns the value of attribute statistics.
-
#td_query ⇒ Object
investigate.
-
#trait1 ⇒ Object
(also: #td_key1)
Returns the value of attribute trait1.
-
#trait2 ⇒ Object
(also: #td_key2)
Returns the value of attribute trait2.
-
#trait3 ⇒ Object
(also: #td_key3)
Returns the value of attribute trait3.
-
#validate ⇒ Object
Returns the value of attribute validate.
-
#validates ⇒ Object
Needs to move into RailsModel.
Instance Method Summary collapse
-
#columns_data ⇒ Object
(also: #rows_fields)
DONE.
-
#columns_data_foreign ⇒ Object
(also: #rows_fields_and_fk)
DONE.
-
#columns_data_foreign_virtual ⇒ Object
DONE.
-
#columns_data_optional ⇒ Object
TODO.
-
#columns_data_primary ⇒ Object
(also: #rows_fields_and_pk)
DONE.
-
#columns_data_required ⇒ Object
TODO.
-
#columns_data_virtual ⇒ Object
(also: #rows_fields_and_virtual)
DONE.
-
#columns_deleted_at ⇒ Object
DONE.
-
#columns_for_structure_types(*structure_types) ⇒ Object
DONE.
-
#columns_foreign ⇒ Object
DONE.
-
#columns_primary ⇒ Object
DONE.
-
#columns_timestamp ⇒ Object
DONE.
-
#columns_virtual ⇒ Object
DONE.
-
#debug(*flags) ⇒ Object
Debug helpers.
- #debug_belongs_to(*flags) ⇒ Object
- #debug_columns(*flags, column_list: columns) ⇒ Object
- #debug_detailed ⇒ Object
- #debug_extra ⇒ Object
- #debug_has_and_belongs_to_many(*flags) ⇒ Object
- #debug_has_many(*flags) ⇒ Object
- #debug_has_one(*flags) ⇒ Object
- #debug_simple ⇒ Object
-
#filter_columns(type_of_columns) ⇒ Object
Filter helpers.
-
#initialize ⇒ Entity
constructor
A new instance of Entity.
- #key? ⇒ Boolean
- #no_key ⇒ Object (also: #keyless?)
- #relations? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Entity
Returns a new instance of Entity.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 80 def initialize @columns = [] @relations = [] @belongs_to = [] @has_one = [] @has_many = [] @has_and_belongs_to_many = [] @rails_model = nil @statistics = nil end |
Instance Attribute Details
#belongs_to ⇒ Object
alias :name :student_name # not wrong, only for getter alias :name= :student_name= # add this for setter alias :name? :student_name? # add this for boolean
64 65 66 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 64 def belongs_to @belongs_to end |
#columns ⇒ Object
Model columns
22 23 24 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 22 def columns @columns end |
#force ⇒ Object
Currently only has the value :cascade
19 20 21 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 19 def force @force end |
#has_and_belongs_to_many ⇒ Object
Returns the value of attribute has_and_belongs_to_many.
67 68 69 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 67 def has_and_belongs_to_many @has_and_belongs_to_many end |
#has_many ⇒ Object
Returns the value of attribute has_many.
66 67 68 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 66 def has_many @has_many end |
#has_one ⇒ Object
Returns the value of attribute has_one.
65 66 67 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 65 def has_one @has_one end |
#id ⇒ Object
16 17 18 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 16 def id @id end |
#main_key ⇒ Object
This entity has a main field that is useful for rendering and may be used for unique constraint, may also be called display_name
28 29 30 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 28 def main_key @main_key end |
#model_type ⇒ Object
Model type - :entity, :basic_user, :admin_user
38 39 40 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 38 def model_type @model_type end |
#name ⇒ Object Also known as: model_name
Name of the entity model
7 8 9 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 7 def name @name end |
#name_plural ⇒ Object Also known as: names
Name of the entity model in plural form
10 11 12 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 10 def name_plural @name_plural end |
#rails_model ⇒ Object
Returns the value of attribute rails_model.
40 41 42 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 40 def rails_model @rails_model end |
#relations_one_to_one ⇒ Object
Model relationships - one_to_one, one_to_many and many_to_many
25 26 27 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 25 def relations_one_to_one @relations_one_to_one end |
#statistics ⇒ Object
Returns the value of attribute statistics.
41 42 43 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 41 def statistics @statistics end |
#td_query ⇒ Object
investigate
35 36 37 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 35 def td_query @td_query end |
#trait1 ⇒ Object Also known as: td_key1
Returns the value of attribute trait1.
30 31 32 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 30 def trait1 @trait1 end |
#trait2 ⇒ Object Also known as: td_key2
Returns the value of attribute trait2.
31 32 33 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 31 def trait2 @trait2 end |
#trait3 ⇒ Object Also known as: td_key3
Returns the value of attribute trait3.
32 33 34 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 32 def trait3 @trait3 end |
#validate ⇒ Object
Returns the value of attribute validate.
71 72 73 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 71 def validate @validate end |
#validates ⇒ Object
Needs to move into RailsModel
70 71 72 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 70 def validates @validates end |
Instance Method Details
#columns_data ⇒ Object Also known as: rows_fields
DONE
146 147 148 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 146 def columns_data @columns_data ||= columns_for_structure_types(:data) end |
#columns_data_foreign ⇒ Object Also known as: rows_fields_and_fk
DONE
187 188 189 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 187 def columns_data_foreign @columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key) end |
#columns_data_foreign_virtual ⇒ Object
DONE
205 206 207 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 205 def columns_data_foreign_virtual @columns_data_foreign_virtual ||= columns_for_structure_types(:data, :foreign_key, :timestamp, :deleted_at) end |
#columns_data_optional ⇒ Object
TODO
152 153 154 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 152 def columns_data_optional @columns_data_optional ||= columns_for_structure_types(:data).select { |_c| true } end |
#columns_data_primary ⇒ Object Also known as: rows_fields_and_pk
DONE
193 194 195 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 193 def columns_data_primary @columns_data_primary ||= columns_for_structure_types(:data, :primary_key) end |
#columns_data_required ⇒ Object
TODO
157 158 159 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 157 def columns_data_required @columns_data_required ||= columns_for_structure_types(:data).select { |_c| false } end |
#columns_data_virtual ⇒ Object Also known as: rows_fields_and_virtual
DONE
199 200 201 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 199 def columns_data_virtual @columns_data_virtual ||= columns_for_structure_types(:data, :timestamp, :deleted_at) end |
#columns_deleted_at ⇒ Object
DONE
177 178 179 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 177 def columns_deleted_at @columns_data_deleted_at ||= columns_for_structure_types(:deleted_at) end |
#columns_for_structure_types(*structure_types) ⇒ Object
DONE
210 211 212 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 210 def columns_for_structure_types(*structure_types) columns.select { |column| structure_types.include?(column.structure_type) } end |
#columns_foreign ⇒ Object
DONE
167 168 169 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 167 def columns_foreign @columns_foreign ||= columns_for_structure_types(:foreign_key) end |
#columns_primary ⇒ Object
DONE
162 163 164 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 162 def columns_primary @columns_primary ||= columns_for_structure_types(:primary_key) end |
#columns_timestamp ⇒ Object
DONE
172 173 174 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 172 def @columns_data_timestamp ||= columns_for_structure_types(:timestamp) end |
#columns_virtual ⇒ Object
DONE
182 183 184 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 182 def columns_virtual @columns_virtual ||= columns_for_structure_types(:timestamp, :deleted_at) end |
#debug(*flags) ⇒ Object
Debug helpers
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 216 def debug(*flags) debug_simple if flags.include?(:simple) debug_detailed if flags.include?(:detailed) debug_extra if flags.include?(:extra) debug_columns(*flags) debug_belongs_to(*flags) debug_has_one(*flags) debug_has_many(*flags) debug_has_and_belongs_to_many(*flags) # log.kv 'relations' , relations end |
#debug_belongs_to(*flags) ⇒ Object
272 273 274 275 276 277 278 279 280 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 272 def debug_belongs_to(*flags) c_simple = flags.include?(:belongs_to_tabular) return unless c_simple && belongs_to.length.positive? log.section_heading('belongs_to') tp belongs_to, :name, :model_name, :model_name_plural, *BelongsTo::KEYS end |
#debug_columns(*flags, column_list: columns) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 252 def debug_columns(*flags, column_list: columns) c_simple = flags.include?(:columns_simple) c_detailed = flags.include?(:columns_detailed) c_extra = flags.include?(:columns_extra) c_tabular = flags.include?(:columns_tabular_simple) || flags.include?(:columns_tabular) c_tabular_detailed = flags.include?(:columns_tabular_detailed) c_tabular_extra = flags.include?(:columns_tabular_extra) return unless c_simple || c_detailed || c_extra || c_tabular || c_tabular_detailed || c_tabular_extra log.section_heading('columns') column_list.each { |column| column.debug(:simple) } if c_simple column_list.each { |column| column.debug(:detailed) } if c_detailed column_list.each { |column| column.debug(:extra) } if c_extra tp column_list, *Column::SIMPLE_ATTRIBS if c_tabular tp column_list, *Column::DETAILED_ATTRIBS if c_tabular_detailed tp column_list, *Column::EXTRA_ATTRIBS if c_tabular_extra end |
#debug_detailed ⇒ Object
236 237 238 239 240 241 242 243 244 245 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 236 def debug_detailed debug_simple log.kv 'id' , id log.kv 'trait1' , trait1 log.kv 'trait2' , trait2 log.kv 'trait3' , trait3 log.kv 'td_query' , td_query log.kv 'key?' , key? log.kv 'no_key' , no_key end |
#debug_extra ⇒ Object
247 248 249 250 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 247 def debug_extra debug_detailed log.kv 'force' , force end |
#debug_has_and_belongs_to_many(*flags) ⇒ Object
302 303 304 305 306 307 308 309 310 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 302 def debug_has_and_belongs_to_many(*flags) c_simple = flags.include?(:has_and_belongs_to_many_tabular) return unless c_simple && has_and_belongs_to_many.length.positive? log.section_heading('has_and_belongs_to_many') tp has_and_belongs_to_many, :name, :model_name, :model_name_plural, *HasAndBelongsToMany::KEYS end |
#debug_has_many(*flags) ⇒ Object
292 293 294 295 296 297 298 299 300 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 292 def debug_has_many(*flags) c_simple = flags.include?(:has_many_tabular) return unless c_simple && has_many.length.positive? log.section_heading('has_many') tp has_many, :name, :model_name, :model_name_plural, *HasMany::KEYS end |
#debug_has_one(*flags) ⇒ Object
282 283 284 285 286 287 288 289 290 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 282 def debug_has_one(*flags) c_simple = flags.include?(:has_one_tabular) return unless c_simple && has_one.length.positive? log.section_heading('has_one') tp has_one, :name, :model_name, :model_name_plural, *HasOne::KEYS end |
#debug_simple ⇒ Object
229 230 231 232 233 234 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 229 def debug_simple log.kv 'name' , name log.kv 'name_plural' , name_plural log.kv 'main_key' , main_key log.kv 'model_type' , model_type end |
#filter_columns(type_of_columns) ⇒ Object
Filter helpers
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 94 def filter_columns(type_of_columns) case type_of_columns when :columns_data columns_data when :columns_data_optional columns_data_optional when :columns_data_required columns_data_required when :columns_data_foreign columns_data_foreign when :columns_primary columns_primary when :columns_foreign columns_foreign when :columns_virtual columns_virtual when :columns_data_foreign_virtual columns_data_foreign_virtual when :columns_data_primary columns_data_primary when :columns_data_virtual columns_data_virtual else columns end end |
#key? ⇒ Boolean
43 44 45 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 43 def key? !main_key.nil? end |
#no_key ⇒ Object Also known as: keyless?
47 48 49 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 47 def no_key main_key.nil? end |
#relations? ⇒ Boolean
73 74 75 76 77 78 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 73 def relations? # log.kv 'has_one', has_one.length # log.kv 'has_many', has_many.length # log.kv 'has_and_belongs_to_many', has_and_belongs_to_many.length has_one.length.positive? || has_many.length.positive? || has_and_belongs_to_many.length.positive? end |
#to_h ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/k_domain/schemas/domain/old/entity.rb', line 121 def to_h { name: name, name_plural: name_plural, type: type, title: title, required: required, structure_type: structure_type, reference_type: reference_type, format_type: format_type, description: description, foreign_key: foreign_key, foreign_table: foreign_table, belongs_to: belongs_to, foreign_id: foreign_id, precision: precision, scale: scale, default: default, null: null, limit: limit, array: array } end |