Module: SuperAuth::Nestable

Included in:
Group, Role
Defined in:
lib/super_auth/nestable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/super_auth/nestable.rb', line 3

def self.included(base)
  base.extend ClassMethods

  base.plugin :rcte_tree, {
    cte_name: base.cte_name(base),
    ancestors: {
      dataset: -> { base.cte(self.id, :asc) }
    },
    descendants: {
      dataset: -> { base.cte(self.parent_id, :desc) }
    }
  }

  base.dataset_module do
    def roots
      self.where(parent_id: nil)
    end

    def trees
      model.cte(nil, :desc)
    end
  end
end