Module: Trees::ClassMethods
- Defined in:
- backend/app/model/mixins/trees.rb
Instance Method Summary collapse
-
#assemble_tree(node, links, properties) ⇒ Object
-
#calculate_object_graph(object_graph, opts = {}) ⇒ Object
-
#node_model ⇒ Object
-
#node_type ⇒ Object
-
#ordered_record_properties(record_ids) ⇒ Object
Default: to be overriden by implementing models.
-
#root_type ⇒ Object
-
#sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
-
#tree_of(root_type, node_type) ⇒ Object
Instance Method Details
#assemble_tree(node, links, properties) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'backend/app/model/mixins/trees.rb', line 328 def assemble_tree(node, links, properties) result = properties[node].clone if !result.has_key?('has_children') result['has_children'] = !!links[node] end if links[node] result['children'] = links[node].sort_by(&:first).map do |position, child_id| assemble_tree(child_id, links, properties) end else result['children'] = [] end result end |
#calculate_object_graph(object_graph, opts = {}) ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'backend/app/model/mixins/trees.rb', line 358 def calculate_object_graph(object_graph, opts = {}) object_graph.each do |model, id_list| next if self != model ids = node_model.any_repo.filter(:root_record_id => id_list). select(:id).map {|row| row[:id] } object_graph.add_objects(node_model, ids) end super end |
#node_model ⇒ Object
323 324 325 |
# File 'backend/app/model/mixins/trees.rb', line 323 def node_model Kernel.const_get(node_type.to_s.camelize) end |
#node_type ⇒ Object
318 319 320 |
# File 'backend/app/model/mixins/trees.rb', line 318 def node_type @node_type end |
#ordered_record_properties(record_ids) ⇒ Object
Default: to be overriden by implementing models
374 375 376 |
# File 'backend/app/model/mixins/trees.rb', line 374 def ordered_record_properties(record_ids) {} end |
#root_type ⇒ Object
313 314 315 |
# File 'backend/app/model/mixins/trees.rb', line 313 def root_type @root_type end |
#sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
347 348 349 350 351 352 353 354 355 |
# File 'backend/app/model/mixins/trees.rb', line 347 def sequel_to_jsonmodel(objs, opts = {}) jsons = super jsons.zip(objs).each do |json, obj| json['tree'] = {'ref' => obj.uri + '/tree'} end jsons end |
#tree_of(root_type, node_type) ⇒ Object
307 308 309 310 |
# File 'backend/app/model/mixins/trees.rb', line 307 def tree_of(root_type, node_type) @root_type = root_type @node_type = node_type end |