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
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'backend/app/model/mixins/trees.rb', line 424 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
454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'backend/app/model/mixins/trees.rb', line 454 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
419 420 421 |
# File 'backend/app/model/mixins/trees.rb', line 419 def node_model Kernel.const_get(node_type.to_s.camelize) end |
#node_type ⇒ Object
414 415 416 |
# File 'backend/app/model/mixins/trees.rb', line 414 def node_type @node_type end |
#ordered_record_properties(record_ids) ⇒ Object
Default: to be overriden by implementing models
470 471 472 |
# File 'backend/app/model/mixins/trees.rb', line 470 def ordered_record_properties(record_ids) {} end |
#root_type ⇒ Object
409 410 411 |
# File 'backend/app/model/mixins/trees.rb', line 409 def root_type @root_type end |
#sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
443 444 445 446 447 448 449 450 451 |
# File 'backend/app/model/mixins/trees.rb', line 443 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
403 404 405 406 |
# File 'backend/app/model/mixins/trees.rb', line 403 def tree_of(root_type, node_type) @root_type = root_type @node_type = node_type end |