Class: Aker::Group

Inherits:
Tree::TreeNode
  • Object
show all
Defined in:
lib/aker/group.rb

Overview

The authority-independent representation of a group.

Groups can be related in a tree. If so, a membership in an ancestor group implies membership in all its descendents.

Instance Method Summary collapse

Constructor Details

#initialize(name, *args) ⇒ Group

Creates a new group with the given name. You can add children using ‘<<`.

Parameters:

  • name (#to_s)

    the desired name

  • args (Array, nil)

    additional arguments. Included for marshalling compatibility with the base class.



21
22
23
# File 'lib/aker/group.rb', line 21

def initialize(name, *args)
  super # overridden to attach docs
end

Instance Method Details

#include?(other) ⇒ Boolean

Determines whether this group or any of its children matches the given parameter for authorization purposes.

Parameters:

  • other (#to_s, Group)

    the thing to compare this group to

Returns:

  • (Boolean)

    true if the name of this group or any of its children is a case-insensitive match for the other.



33
34
35
36
37
38
39
40
# File 'lib/aker/group.rb', line 33

def include?(other)
  other_name =
    case other
    when Group; other.name;
    else other.to_s;
    end
  self.find { |g| g.name.downcase == other_name.downcase }
end

#marshal_load(dumped_tree_array) ⇒ Object

Copy-pasted from parent in order to use appropriate class when deserializing children.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/aker/group.rb', line 47

def marshal_load(dumped_tree_array)
  nodes = { }

  for node_hash in dumped_tree_array do
    name        = node_hash[:name]
    parent_name = node_hash[:parent]
    content     = Marshal.load(node_hash[:content])

    if parent_name then
      nodes[name] = current_node = self.class.new(name, content)
      nodes[parent_name].add current_node
    else
      # This is the root node, hence initialize self.
      initialize(name, content)

      nodes[name] = self    # Add self to the list of nodes
    end
  end
end