Module: Structureable

Defined in:
app/models/structureable.rb

Overview

This module provides the ActiveRecord::Base extension ‘is_structureable`, which characterizes a model as part of the global dag_link structure in this project. All structureable objects are nodes of this dag link.

Examples:

@page1.parent_pages << @page2
@page1.parents # => [ @page2, ... ]

@group.child_users << @user
@group.children # => [ @user, ... ]
@user.parents # => [ @group, ... ]

For all methods that are provided, please consult the documentations of the ‘acts-as-dag` gem and of the `acts_as_paranoid_dag` gem.

This module is included in ActiveRecord::Base via an initializer at config/initializers/active_record_structureable_extension.rb

Defined Under Namespace

Modules: StructureableInstanceMethods

Instance Method Summary collapse

Instance Method Details

#is_structureable(options = {}) ⇒ Object

This method is used to declare a model as structureable, i.e. part of the global dag link structure.

Options:

ancestor_class_names
descendant_class_names
link_class_name         (default: 'DagLink')

For detailed information on the options, please see the documentation of the ‘acts-as-dag` gem, since these options are forwarded to the has_dag_links method. rubydoc.info/github/resgraph/acts-as-dag/Dag#has_dag_links-instance_method

Example:

class Group < ActiveRecord::Base
  is_structureable ancestor_class_names: %w(Group), descendant_class_names: %w(Group User)
end
class User < ActiveRecord::Base
  is_structureable ancestor_class_names: %w(Group)
end


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/structureable.rb', line 45

def is_structureable( options = {} )
  
  # default options
  conf = {
    :link_class_name => 'DagLink'
  }
  conf.update( options )

  # the model is part of the dag link structure. see gem `acts-as-dag`
  has_dag_links    conf

  
  before_destroy   :destroy_links

  # see Flagable model.
  has_many_flags

  # Structureable objects may have special_groups as descendants, e.g. the admins_parent group.
  # This mixin loads the necessary methods to interact with them.
  #
  include StructureableMixins::HasSpecialGroups
  
  # To use `prepend` here allows to call `super` in the methods
  # defined in the module `StructureableInstanceMethods`.
  #
  prepend StructureableInstanceMethods
end